Compare commits

...
130 Commits
Author SHA1 Message Date
Michael Tokarev aeec49e817 Update version for 11.0.3 release
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-24 10:05:23 +03:00
Alex Bennée 43a9a54261 target/arm: do not clear halting reason in has_work helper
The helper will be called multiple times as we exit a loop and until
we actually restart (via arm_cpu_exec_halt) we should leave the
condition the same.

Fixes: 6fd2fcdc61 (target/arm: teach arm_cpu_has_work about halting reasons)
Fixes: aefafd403b in 11.0.x series
Reviewed-by: Peter Maydell <[email protected]>
Signed-off-by: Alex Bennée <[email protected]>
Reviewed-by: Richard Henderson <[email protected]>
Message-id: [email protected]
Signed-off-by: Peter Maydell <[email protected]>
(cherry picked from commit c2804566f6)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-23 00:10:02 +03:00
Alex Bennée aefafd403b target/arm: teach arm_cpu_has_work about halting reasons
With the advent of WFE and WFI we need to pay closer attention to the
reason why the vCPU may be sleeping to figure out if we should wake
it up.

Create env->halt_reason to track this and then re-order the tests so
we:

  - ignore everything is the vCPU is powered off
  - wake up if the event_register is set and we were in a WFE
  - otherwise any IRQ event does wake the vCPU up.

Reviewed-by: Richard Henderson <[email protected]>
Signed-off-by: Alex Bennée <[email protected]>
Message-id: [email protected]
Signed-off-by: Peter Maydell <[email protected]>
(cherry picked from commit 6fd2fcdc61)
(Mjt: context fixups in target/arm/cpu.h target/arm/internals.h)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-23 00:01:18 +03:00
Haotian Jiang d0fc841534 hw/audio/intel-hda: restrict all DMA engine paths to memories
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)")
Reported-by: Haotian Jiang of Tencent Security (Yunding Lab) <[email protected]>
Signed-off-by: Haotian Jiang <[email protected]>
Cc: [email protected]
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Message-ID: <[email protected]>
Signed-off-by: Philippe Mathieu-Daudé <[email protected]>
(cherry picked from commit c257745248)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-22 12:41:12 +03:00
Bin Meng 6944c6b861 hw/net/cadence: Return current Cadence GEM queue pointers
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: e9f186e514 ("cadence_gem: initial version of device model")
Fixes: 6710172501 ("cadence_gem: Add queue support")
Cc: [email protected]
Signed-off-by: Bin Meng <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Message-ID: <[email protected]>
Signed-off-by: Philippe Mathieu-Daudé <[email protected]>
(cherry picked from commit 94c510a5dc)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-22 12:41:12 +03:00
Philippe Mathieu-Daudé 64749657fe hw/misc/applesmc: Fix a typo setting MSSD key
In commit 1ddda5cd36 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.

Cc: [email protected]
Fixes: 1ddda5cd36 ("AppleSMC device emulation")
Reported-by: Matthew Jackson <[email protected]>
Signed-off-by: Philippe Mathieu-Daudé <[email protected]>
Reviewed-by: Alexander Graf <[email protected]>
Reviewed-by: Pierrick Bouvier <[email protected]>
Message-Id: <[email protected]>
(cherry picked from commit 2142689d92)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-22 12:41:12 +03:00
Marc-André Lureau d605d2769b replay: fix use of uninitialized pointer on error
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: f6baed3d14 ("replay: implement replay-seek command")
Signed-off-by: Marc-Andre Lureau <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Message-ID: <[email protected]>
Signed-off-by: Philippe Mathieu-Daudé <[email protected]>
(cherry picked from commit fe68e4b47b)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-22 12:41:12 +03:00
Marc-André Lureau f34830aa81 hw/display/qxl: validate monitors_config heads[] in phys2virt
The qxl_phys2virt() call for guest_monitors_config only validates
sizeof(QXLMonitorsConfig), which covers the fixed header (count and
max_allowed) since commit 8efec0ef8b ("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
Reported-by: Tristan @TristanInSec
Signed-off-by: Marc-Andre Lureau <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Message-ID: <[email protected]>
Signed-off-by: Philippe Mathieu-Daudé <[email protected]>
(cherry picked from commit 9f436938c5)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-22 12:41:12 +03:00
Peter Maydell ee17866605 net: Correct padding check in qemu_receive_packet()
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 a01344d9d7 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.

Cc: [email protected]
Fixes: a01344d9d7 ("net: pad packets to minimum length in qemu_receive_packet()")
Suggested-by: Bin Meng <[email protected]>
Signed-off-by: Peter Maydell <[email protected]>
Reviewed-by: Bin Meng <[email protected]>
Message-ID: <[email protected]>
Signed-off-by: Philippe Mathieu-Daudé <[email protected]>
(cherry picked from commit b1e73b2ddb)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-22 12:41:12 +03:00
Jay Chang 9e4f8a8cbb hw/net/xilinx_axienet: Fix PHY register 17 link status reporting
The Marvell 88E1111 PHY register 17 (PHY Specific Status Register)
bit 10 reports real-time link status. Previously, this register
returned a fixed value of 0x8800 with bit 10 always cleared,
causing U-Boot to always detect "No link" even when the link
was up.

Signed-off-by: Jay Chang <[email protected]>
Reviewed-by: Frank Chang <[email protected]>
Message-id: [email protected]
Reviewed-by: Peter Maydell <[email protected]>
Signed-off-by: Peter Maydell <[email protected]>
(cherry picked from commit 8392734722)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-22 12:41:12 +03:00
Thomas Huth 2a5bc4de0f hw/usb/hcd-xhci-sysbus: Fix OOB heap access in xhci_sysbus_intr_raise()
Some machines like the microvm machine instantiate a "sysbus-xhci"
device with just 1 interrupt (by setting the "intrs" property to 1).
xhci_sysbus_realize() then only allocates the s->irq array with one
entry.

When the guest writes to the ERDP register of a corresponding XHCI
"interrupter", the generic XHCI code calls the xhci_sysbus_intr_raise()
function with n > 1, and this function then calls qemu_set_irq() with
s->irq[n] pointing to a bad heap address. The qemu_set_irq() then tries
to call an IRQ handler via a function pointer in that heap space. This
either causes QEMU to die with a segmentation fault (if it's a bad
address), or even worse runs some unexpected code if the destination
of the pointer is executable code.

Looking at the xHCI spec, it is up to the implementation of the host
controller how many interrupters are available. So if we only support
one or some few interrupters, the registers of the other interrupters
should not do anything, i.e. reads should result in zeros and writes
should be completely ignored. (big thanks to Peter Maydell for helping
with the analyzation of the correct way to fix this here)

This way, the xhci_sysbus_intr_raise() function cannot be called with
an invalid interrupt number anymore. But for good measure, also add an
assert() statement to the xhci_sysbus_intr_raise() function to prevent
that similar problems with calling arbitrary function pointers on the
heap could occur again.

Fixes: CVE-2026-16043
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4001
Reported-by: Tristan Madani <[email protected]>
Reviewed-by: Peter Maydell <[email protected]>
Signed-off-by: Thomas Huth <[email protected]>
Message-ID: <[email protected]>
(cherry picked from commit cc479aa897)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-21 00:02:25 +03:00
Thomas Huth 46ab8d7b90 hw/usb/hcd-xhci: Fix guest-triggerable assert() in xhci_find_stream()
The assert() statement in xhci_find_stream() can be triggered by
the guest (see bug tickets #273, #3895 and #3988 on gitlab.com).
Turn it into a qemu_log_mask() instead to fix this problem.

Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/273
Reviewed-by: Peter Maydell <[email protected]>
Signed-off-by: Thomas Huth <[email protected]>
Message-ID: <[email protected]>
(cherry picked from commit 4daeaa2fe0)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-21 00:02:25 +03:00
Marc-André Lureau 1e54185745 usbredir: fix infinite loop and SIGFPE with zero max_packet_size
A malicious usbredir peer can send an ep_info message resetting
max_packet_size to 0 after bulk receiving has started. This causes:
- infinite loop in usbredir_buffered_bulk_packet() where the splitting
  loop increments by max_packet_size (0)
- SIGFPE in usbredir_buffered_bulk_in_complete_ftdi() from modulo by 0
- SIGFPE in usbredir_handle_buffered_bulk_in_data() from division by 0
  when computing bytes_per_transfer

Fix by stopping and disabling bulk receiving in usbredir_ep_info() when
max_packet_size is set to 0.

Add post-load check, and assert() for the invariant.

Fixes: CVE-2026-63319
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3995
Reported-by: Tristan @TristanInSec
Signed-off-by: Marc-André Lureau <[email protected]>
Reviewed-by: Thomas Huth <[email protected]>
Message-ID: <[email protected]>
Signed-off-by: Thomas Huth <[email protected]>
(cherry picked from commit a002485bfe)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-21 00:02:25 +03:00
Marc-André Lureau 6229fbcef1 usbredir: fix use-after-free on buffered bulk packet overflow
When usbredir_buffered_bulk_packet() splits a multi-fragment buffered
bulk packet into max-packet-size chunks, only the final fragment owns
the shared parser allocation (via free_on_destroy). If bufp_alloc()
drops the final fragment due to queue overflow, it frees the backing
buffer while earlier fragments already queued still hold interior
pointers into it. Subsequent guest bulk-IN transfers then read from
freed heap memory.

Fix this by tracking how many fragments were queued during the current
packet. When bufp_alloc() fails, remove all already-queued fragments
from the tail of the endpoint queue before breaking out of the loop.
If the dropped fragment was non-final, free the data buffer explicitly
since no fragment took ownership.

Fixes: CVE-2026-15705
Fixes: b2d1fe67d0 ("usbredir: Add support for buffered bulk input (v2)")
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3808
Reported-by: Feifan Qian <[email protected]>
Signed-off-by: Marc-André Lureau <[email protected]>
Message-ID: <[email protected]>
Signed-off-by: Thomas Huth <[email protected]>
(cherry picked from commit 9bf52d056a)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-21 00:02:25 +03:00
Xiangfeng Cai 99a1c3b636 tests/qtest: add xhci-pci unplug finalize regression test
Add a qtest that hot-adds an nec-usb-xhci controller, requests unplug,
resets the system to process the request, and waits for DEVICE_DELETED.
This covers the xHCI PCI host-link refcount cycle by verifying that
device_finalize() runs after unplug.

Signed-off-by: Xiangfeng Cai <[email protected]>
Message-ID: <[email protected]>
Signed-off-by: Thomas Huth <[email protected]>
(cherry picked from commit ba54d7e66e)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-21 00:02:25 +03:00
Xiangfeng Cai e9423caa27 hw/usb/hcd-xhci-pci: break host link cycle so device_finalize() runs on unplug
The xHCI PCI wrapper embeds an xhci-core child via object_initialize_child()
and, in usb_xhci_pci_realize(), points the child's "host" link back at the PCI
device:

    object_property_set_link(OBJECT(&s->xhci), "host", OBJECT(s), NULL);

"host" is a DEFINE_PROP_LINK property, which qdev registers as an
OBJ_PROP_LINK_STRONG link. A strong link takes a reference on its target, so
this creates a refcount cycle: the PCI device owns the child, and the child's
strong link pins the PCI device.

On unplug (guest ACPI eject or QMP device_del), pci_qdev_unrealize() calls
pc->exit() but never unrealizes the no-bus child. object_unparent() then drops
only the parent/bus references, leaving the link reference in place. The PCI
device stays at refcount 1 forever, so object_finalize()/device_finalize() is
never reached. Symptom observed under gdb after eject:

    p *((Object *)dev)  =>  ref = 1, parent = 0x0, realized = false
    p ((XHCIPciState *)dev)->xhci.hostOpaque  =>  points back at dev

Fix usb_xhci_pci_exit() to tear down the embedded child explicitly: unrealize
it first (so the set-link-before-realize check passes), then clear the "host"
link. This releases the strong reference, lets the PCI device refcount reach 0,
and allows device_finalize() to run.

Fixes: 8ddab8dd3d ("usb/hcd-xhci: Split pci wrapper for xhci base model")
Signed-off-by: Xiangfeng Cai <[email protected]>
Acked-by: Marc-André Lureau <[email protected]>
Message-ID: <[email protected]>
Signed-off-by: Thomas Huth <[email protected]>
(cherry picked from commit 054ef33f67)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-21 00:02:25 +03:00
Feifan Qian 4612a7d02b hw/usb/xhci: clamp interval exponent to avoid UB shift in xhci_init_epctx()
The xHCI endpoint context dword 0 bits 23:16 ("Interval") are written
by the guest and passed directly as the shift amount in:

    epctx->interval = 1 << ((ctx[0] >> 16) & 0xff);

The shift amount can be 0-255.  Shifting a 32-bit `int` left by >= 32
is undefined behaviour under C11 §6.5.7p4.  With UBSan
(halt_on_error=1) this causes QEMU to abort; with aggressive compiler
optimisations that assume UB is unreachable the result is
unpredictable.

Clamp the exponent to [0, 18] with MIN() before the shift, and use
`1u` (unsigned) to avoid shifting a signed integer.  The xHCI
specification defines a maximum meaningful Interval value of 18 for
most endpoint types; thus clamping to 18 is a safe fix that
preserves the full unsigned 32-bit range for any compliant value.

Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3703
Reported-by: Feifan Qian <[email protected]>
Signed-off-by: Feifan Qian <[email protected]>
[thuth: Clamp to 18 instead of 31]
Signed-off-by: Thomas Huth <[email protected]>
(cherry picked from commit 12d8ee9d53)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-21 00:02:25 +03:00
Alex Bennée df91e7249b accel/tcg: move jit thread manipulation into do_tb_phys_invalidate
To invalidate a TB on MacOS we need to enable write access to the JIT
buffer. We were doing this for tb_phys_invalidate__locked but that is
not the only path into do_tb_phys_invalidate. Move the manipulation
into the shared function that does the work.

As a result we can drop the tb_phys_invalidate__locked function and
update the calls directly.

This enables watchpoints to work in MacOS TCG guests.

Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3444
Reviewed-by: Richard Henderson <[email protected]>
Message-ID: <[email protected]>
Signed-off-by: Alex Bennée <[email protected]>
(cherry picked from commit 78420b59f0)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-21 00:02:25 +03:00
Akihiko Odaki cb1b5319cb hw/display/virtio-gpu: Check pixman_image_create_bits() results
pixman_image_create_bits() returns NULL for allocation failures and
unaligned strides, which may be supplied by the guest with
VIRTIO_GPU_CMD_SET_SCANOUT_BLOB, and virtio_gpu_do_set_scanout()
subsequently dereferences it.

Fixes: fa06e5cb7b ("virtio-gpu: fix scanout rectangles")
Signed-off-by: Akihiko Odaki <[email protected].i.u-tokyo.ac.jp>
Reviewed-by: Marc-André Lureau <[email protected]>
Message-ID: <[email protected].i.u-tokyo.ac.jp>
(cherry picked from commit f1af81ba2a)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-21 00:02:25 +03:00
Marc-André Lureau 4403b3db64 hw/display/virtio-gpu: handle migration iov allocation failure
An unbounded iov_cnt from the migration stream drives two g_new()
allocations whose combined size can exceed available memory, causing
GLib to abort the process.

Switch to g_try_new() and propagate the failure as a migration error.

Fixes: 0c244e50ee ("virtio-gpu: add live migration support")
Fixes: f66767f75c ("virtio-gpu: add virtio-gpu/blob vmstate subsection")
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3753
Reported-by: Feifan Qian <[email protected]>
Reviewed-by: Akihiko Odaki <[email protected].i.u-tokyo.ac.jp>
Signed-off-by: Marc-André Lureau <[email protected]>
(cherry picked from commit e99488c5d4)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-21 00:02:25 +03:00
Marc-André Lureau 7e6c76474e hw/display/virtio-gpu: cap submit_3d command buffer allocation
Both virgl_cmd_submit_3d() and rutabaga_cmd_submit_3d() pass the
guest-controlled cs.size directly to malloc() without bounds checking. A
malicious guest can set cs.size to an arbitrarily large value, causing
an OOM abort that crashes the QEMU process.

Checking cs.size against the descriptor payload length (iov_size) is not
sufficient: indirect descriptor tables can repeat entries aliasing the
same guest-physical range, inflating iov_size() to nearly 4 GiB while
referring to only a small amount of unique memory.

Instead, cap cs.size at 4 MiB. With 4 KiB pages and QEMU's
VIRTQUEUE_MAX_SIZE (1024) mapped-iov limit, the Linux virtio driver
cannot carry more than ~4 MiB of inline command data, so legitimate
submissions are unaffected.

Fixes: 9d9e152136 ("virtio-gpu: add 3d mode and virgl rendering support.")
Fixes: 1dcc6adbc1 ("gfxstream + rutabaga: add initial support for gfxstream")
Fixes: d52c454aad ("contrib: add vhost-user-gpu")
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3776
Reported-by: [email protected]
Reviewed-by: Akihiko Odaki <[email protected].i.u-tokyo.ac.jp>
Signed-off-by: Marc-André Lureau <[email protected]>
(cherry picked from commit 8720061c6d)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-21 00:02:25 +03:00
Marc-André Lureau 147e214e9c ui/vnc: validate SetPixelFormat field ranges
The VNC SetPixelFormat message carries red/green/blue_max as 16-bit
values, but PixelFormat stores them as uint8_t. A client sending a
max value above 255 (e.g. 0x0100) passes the existing non-zero check
but silently truncates to 0 on assignment, leading to a division by
zero in the Tight PNG palette path.

Add explicit range checks if any channel max exceeds UINT8_MAX.

Fixes: CVE-2026-15578
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3976
Reported-by: dong ling
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Reviewed-by: Daniel P. Berrangé <[email protected]>
Signed-off-by: Marc-Andre Lureau <[email protected]>
(cherry picked from commit 6075444c5a)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-21 00:02:25 +03:00
Marc-André Lureau 24767bcf0f ui/vnc: fix out-of-bounds write in lossy refresh dirty marking
vnc_refresh_lossy_rect() marks a full VNC_STAT_RECT (64) rows of the
dirty bitmap when refreshing a lossy tile. When the display height is
not a multiple of VNC_STAT_RECT, the last tile row is a partial tile and
the loop writes past the end of vs->dirty[VNC_MAX_HEIGHT].

For example, with a 2160-pixel-high display (VNC_MAX_HEIGHT), the last
stat tile starts at y=2112. The unconditional 64-row loop writes rows
2112..2175, overflowing 16 rows (640 bytes) past the dirty bitmap into
subsequent VncState fields.

Fix by passing the effective display height into
vnc_refresh_lossy_rect() and clamping the inner loop.

Fixes: CVE-2026-61475
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3935
Reported-by: "Vulnerability Report" <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Signed-off-by: Marc-Andre Lureau <[email protected]>
(cherry picked from commit e650e4fe0f)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-21 00:02:25 +03:00
Akihiko Odaki 8cfd68c4b2 ui/gtk: Narrow DMA-BUF critical section
Scanout operations need to be properly ordered to avoid tearing. The
virtio specification allows the guest to use pageflip. With pageflip,
the guest only modifies the invisible framebuffer while the host scans
out the visible framebuffer. The guest may choose not to use pageflip to
avoid its overhead, accepting the risk of tearing.

ui/gtk performs the following procedure to flush a scanout:
1) Queue a draw event.
2) The draw event gets triggered.
3) Blit the guest framebuffer to the host framebuffer.

When flushing a DMA-BUF scanout, ui/gtk blocks the device before 2) if
possible and unblocks it after 3) to enforce proper ordering. However,
blocking the device before 2) has two problems.

First, it can leave the device blocked indefinitely because GTK
sometimes decides to cancel 2) when the window is not visible for
example. ui/gtk regularly repeats 1) as a workaround, but it is not
applicable to GtkGLArea because it causes display corruption.

Second, the behavior is inconsistent with the other types of scanout
that leave the device unblocked between 1) and 2).

To fix these problems, let ui/gtk block the device only when the
queued draw event runs, immediately before 3). Blocking before that is
unnecessary since ui/gtk does not access the framebuffer yet. If the
guest does not use pageflip but instead updates the visible framebuffer
directly, ui/gtk should not add the overhead of a pre-draw block.

ui/gtk still blocks the device during 3) for DMA-BUF. Unlike the other
scanout types, 3) can happen asynchronously with the device for a
DMA-BUF, so ui/gtk needs to keep the visible guest framebuffer stable
for the blit.

With the problems fixed, the workaround to repeat 1) is no longer
necessary and is removed.

Signed-off-by: Akihiko Odaki <[email protected].i.u-tokyo.ac.jp>
Acked-by: Marc-André Lureau <[email protected]>
Message-ID: <[email protected].i.u-tokyo.ac.jp>
(cherry picked from commit 53f0d87db7)
(Mjt: back-port to before v11.0.0-787-g405a42e3655
 "ui/console: rename public API to use consistent qemu_console_ prefix" which
 renamed graphic_hw_gl_block() to qemu_console_hw_gl_block())
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-21 00:02:25 +03:00
Marc-André Lureau f145c5d2e0 ui/input-barrier: fix off-by-one in keycode bounds check
Use strict "<" to fix the off-by-one.

Fixes: 6105683da3 ("ui: add an embedded Barrier client")
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3951
Reported-by: huntr bubble
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Reviewed-by: Laurent Vivier <[email protected]>
Signed-off-by: Marc-Andre Lureau <[email protected]>
(cherry picked from commit 82b4d693d5)
(Mjt: fixup the change to before v11.0.0-365-gd276ad86eb8
 "ui: rename init_keyboard_layout->kbd_layout_new()")
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-21 00:02:25 +03:00
Marc-André Lureau 17c60da3e8 ui/vnc: validate color shifts in SetPixelFormat
A malicious VNC client can send a SetPixelFormat message with shift
values >= 32, causing UB mask computation
(e.g. red_max << red_shift where red_shift is 255). Apparently, this is
not covered by -fwrapv.

Reject color shifts >= bits_per_pixel || 32 before computing masks.

Fixes: 9f64916da2 ("pixman/vnc: use pixman images in vnc.")
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3948
Reported-by: huntr bubble
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Signed-off-by: Marc-Andre Lureau <[email protected]>
(cherry picked from commit fb71c895d7)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-21 00:02:25 +03:00
Marc-André Lureau 738927b263 ui/vnc: fix OOB write in vnc_refresh_lossy_rect
vnc_refresh_lossy_rect() always marks a full VNC_STAT_RECT (64) rows
as dirty when refreshing a lossy tile. When the display height is not
a multiple of VNC_STAT_RECT (e.g. VNC_MAX_HEIGHT = 2160), the bottom
tile is partial -- the last tile at y=2112 has only 48 valid rows.
The unclamped loop writes to vs->dirty[2160..2175], past the end of
the VNC_MAX_HEIGHT-sized array.

Clamp the row count to the actual surface height so partial bottom
tiles only mark valid dirty bitmap entries.

Fixes: CVE-2026-48002
Fixes: 7d964c9d2f ("vnc: refresh lossy rect after a given timeout")
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3950
Reported-by: huntr bubble
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Signed-off-by: Marc-Andre Lureau <[email protected]>
(cherry picked from commit 3543c2b855)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-21 00:02:25 +03:00
Rohitashv Kumar 76295c4f3e net: only advertise passt in netdev help when CONFIG_PASST
show_netdevs() lists each conditionally-compiled netdev backend behind
its CONFIG_* guard (CONFIG_SLIRP for "user", CONFIG_L2TPV3 for
"l2tpv3", CONFIG_NET_BRIDGE for "bridge", ...). The "passt" entry was
added unconditionally, so "-netdev help" advertises passt even in
builds configured with --disable-passt. Trying to use it then fails
with "Parameter 'type' does not accept value 'passt'", since the QAPI
NetClientDriver enum member "passt" is gated by 'if': 'CONFIG_PASST'.

Guard the help entry with CONFIG_PASST so the advertised backends match
those actually compiled into the binary.

Signed-off-by: Rohitashv Kumar <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Reviewed-by: Puranjay Mohan <[email protected]>
Message-ID: <[email protected]>
Signed-off-by: Philippe Mathieu-Daudé <[email protected]>
(cherry picked from commit 504f2bad93)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-21 00:02:25 +03:00
Thomas Huth c548cb660d hw/usb/hcd-xhci: Turn guest-triggerable abort() into qemu_log_mask()
The FIXME macros in xhci_alloc_device_streams() can be triggered
by a (malicious) guest. Since the macro also contains an abort()
statement, this terminates QEMU. Turn the FIXME statements into
a qemu_log_mask() instead to avoid that a guest can shoot itself
this way.

Reported-by: Feifan Qian <[email protected]>
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3784
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Signed-off-by: Thomas Huth <[email protected]>
Message-ID: <[email protected]>
Signed-off-by: Philippe Mathieu-Daudé <[email protected]>
(cherry picked from commit 5257259428)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-21 00:02:25 +03:00
Thomas Huth abf441a580 hw/usb/hcd-ohci: Make sure that ohci_service_ed_list() cannot loop forever
The inner while loop in ohci_service_ed_list() could theoretically
loop forever if a malicious guest prepares a set of bad descriptors.
Add a check to the loop to avoid this situation.

Reported-by: Feifan Qian <[email protected]>
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3781
Signed-off-by: Thomas Huth <[email protected]>
Reviewed-by: Daniel P. Berrangé <[email protected]>
Message-ID: <[email protected]>
Signed-off-by: Philippe Mathieu-Daudé <[email protected]>
(cherry picked from commit 98e5a8eb4f)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-21 00:02:25 +03:00
Marc-André Lureau ea4f6fb68b hw/display/virtio-gpu: fix dmabuf_fd leak on remap failure
When virtio_gpu_create_udmabuf() succeeds but virtio_gpu_remap_udmabuf()
fails (mmap returns MAP_FAILED), virtio_gpu_init_udmabuf() returns early
without closing the dmabuf fd. Since res->blob is never set in this
path, later cleanup via virtio_gpu_cleanup_mapping() skips
virtio_gpu_fini_udmabuf() entirely, leaking the file descriptor.

Call virtio_gpu_destroy_udmabuf() before the early return to close
the fd. This function already handles partial state correctly: it
skips the munmap when res->remapped is NULL and closes the fd when
res->dmabuf_fd >= 0.

Fixes: 9b60cdf987 ("virtio-gpu: Add udmabuf helpers")
Signed-off-by: Marc-André Lureau <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Reviewed-by: Dmitry Osipenko <[email protected]>
Reviewed-by: Akihiko Odaki <[email protected].i.u-tokyo.ac.jp>
Message-ID: <[email protected]>
Signed-off-by: Philippe Mathieu-Daudé <[email protected]>
(cherry picked from commit 564c4d7e99)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-21 00:02:25 +03:00
Miao Wang f3248e1e19 hw/scsi/vmw_pvscsi: add a comment to explain the endianness
Add a comment to explain the endianness of the pvscsi device. We have
no information about the endianness should be little-endian or CPU
native endian because the current driver code is designed to work only
on x86 and is not endianness aware. We assume that the pvscsi device is
implicitly little-endian.

Signed-off-by: Miao Wang <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Message-ID: <[email protected]>
Signed-off-by: Philippe Mathieu-Daudé <[email protected]>
(cherry picked from commit ecc569639a)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-21 00:02:25 +03:00
Miao Wang 7ea8410cab hw/scsi/vmw_pvscsi: translate data endianness
This patch improves the implementation of the pvscsi device by
translating the endianness of the data sent or received from the guest.
This ensures pvscsi can work on big-endian hosts with little-endian
guests.

This patch assumes, although not having found any specifications, that
the pvscsi device is little-endian, since pvscsi seems to be used only
on x86 platforms, which are little-endian.

Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Signed-off-by: Miao Wang <[email protected]>
Message-ID: <[email protected]>
[PMD: Rebased on top of commit cb30b8758d physmem API conversion]
Signed-off-by: Philippe Mathieu-Daudé <[email protected]>
(cherry picked from commit 5a811329bd)
(Mjt: re-rebased to before commit cb30b8758d physmem API conversion)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-21 00:02:25 +03:00
Dmitry Pimenov 772c0f54d8 hw/sparc64/niagara: use int64_t for vdisk size to avoid truncation
blk_getlength() returns int64_t, but niagara_init() stored it in an int,
truncating the if=pflash virtual-ramdisk size for images >= 2 GiB. A ~4 GiB
image truncated to 0/negative, failed the `size > 0` check, and exit(1)'d
before the CPU ran, ending with:

  qemu-system-sparc64: could not load ram disk

Signed-off-by: Dmitry Pimenov <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Message-ID: <[email protected]>
Signed-off-by: Philippe Mathieu-Daudé <[email protected]>
(cherry picked from commit 76dbe26fd6)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-21 00:02:25 +03:00
Marc-André Lureau 3f247bed37 hw/display/qxl: fix TOCTOU in cursor chunk data_size handling
Snapshot chunk.data_size into a host-local variable before passing it to
qxl_phys2virt() for validation, and pass it through qxl_cursor() and
qxl_unpack_chunks() so that no subsequent code re-reads the field.

Without this, a racing vCPU can inflate data_size between the
qxl_phys2virt() validation and the memcpy in qxl_unpack_chunks(),
causing a source read past the validated region. In practice the read
stays within the guest's own VRAM mmap, so the impact is limited.

Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3757
Reported-by: Feifan Qian <[email protected]>
Signed-off-by: Marc-Andre Lureau <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Message-ID: <[email protected]>
Signed-off-by: Philippe Mathieu-Daudé <[email protected]>
(cherry picked from commit a3cc0069e1)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-21 00:02:25 +03:00
Haotian Jiang e1fb448981 hw/misc/ivshmem: clear chardev handlers before freeing peers
ivshmem_exit() frees s->peers and s->msi_vectors but does not clear
the chardev handlers registered in ivshmem_common_realize(). Those
handlers are only removed later in object_finalize() via release_chr,
which runs after ivshmem_exit().

Between exit and finalize, ivshmem_read() can fire on pending chardev
data and process_msg_connect() dereferences the freed s->peers.
Additionally, s->peers, s->nb_peers, and s->msi_vectors are not
zeroed after free, leaving dangling pointers that make the UAF code
paths reachable.

Fix by clearing chardev handlers at the beginning of ivshmem_exit(),
before any resources they access are freed, and nullifying freed
pointers.

Cc: [email protected]
Fixes: f64a078d45 ("ivshmem: fix pci_ivshmem_exit()")
Link: https://gitlab.com/qemu-project/qemu/-/work_items/3594
Reported-by: Haotian Jiang <[email protected]>
Signed-off-by: Haotian Jiang <[email protected]>
Message-ID: <[email protected]>
Signed-off-by: Philippe Mathieu-Daudé <[email protected]>
(cherry picked from commit 5157ceb10c)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-21 00:02:25 +03:00
Matt Turner 892ccda45a linux-user/alpha: populate AT_HWCAP from env->amask
Alpha has never set AT_HWCAP in linux-user emulation, so getauxval(AT_HWCAP)
always returned 0 regardless of the emulated CPU model.

The Linux kernel computes ELF_HWCAP as ~amask(-1), i.e. the set of ISA
extension bits that the amask instruction reports as supported (cleared in
its output).  env->amask stores exactly those bits with the same layout
(BWX=0x1, FIX=0x2, CIX=0x4, MVI=0x100, TRAP=0x200, PREFETCH=0x1000), so
returning it directly from get_elf_hwcap matches the kernel convention.

Add HAVE_ELF_HWCAP to target_elf.h and implement get_elf_hwcap() in
elfload.c to expose the emulated CPU's capability mask to user-space
programs via the auxiliary vector.

Without this fix, programs using getauxval(AT_HWCAP) to detect BWX/FIX/CIX
(such as glibc's memcpy or JIT compilers targeting Alpha) incorrectly
concluded that no extensions were available even when emulating ev56+.

Signed-off-by: Matt Turner <[email protected]>
Cc: [email protected]
Reviewed-by: Helge Deller <[email protected]>
Signed-off-by: Helge Deller <[email protected]>
(cherry picked from commit 7a2e863f9d)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-15 12:56:43 +03:00
Matt Turner 952ada9117 linux-user/alpha: add coredump support
Define HAVE_ELF_CORE_DUMP and target_elf_gregset_t in target_elf.h,
mirroring the kernel's elf_gregset_t (ELF_NGREG = 66): r0-r31
[0..31], f0-f31 [32..63], pc [64], unique [65].  Implement
elf_core_copy_regs() in elfload.c to populate the gregset from
CPUAlphaState.

Without this, bprm->core_dump is NULL for Alpha targets.  When a
guest signal goes unhandled, dump_core_and_abort() skips the core
write and falls through to die_with_signal(), which re-raises the
signal to the host.  The host kernel then writes an x86-64 core file
for the qemu-alpha process instead of an Alpha guest core.

v2: Store thread unique field, same as in Linux kernel. Added by Helge &
suggested by Richard.

Signed-off-by: Matt Turner <[email protected]>
Signed-off-by: Helge Deller <[email protected]>
Reviewed-by: Richard Henderson <[email protected]>
(cherry picked from commit 9db18ed063)
(Mjt: pick this for -stable too, helps with debugging and makes subsequent
 changes to apply cleanly)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-15 12:56:43 +03:00
Eric Farman 9e3e2bdd71 s390x/css: firm up handling of chained TIC CCWs
The logic in css_interpret_ccw() correctly returns -EINVAL if a
Transfer-In-Channel (TIC) CCW is command chained to another TIC CCW.
The same routine also correctly returns -EINVAL if 256 CCWs do not
perform a data transfer as part of the I/O operation [0].

What is missing, however, is a combination of these two, where a loop
can be generated that will continue processing CCWs but without
providing an opportunity to catch a breath. Fix this by capping
the number of TIC CCWs in a channel program at the same limit as
the CCWs without data transfer.

[0] See "Invalid Sequence" in z/Architecture Principles of Operation
    (SA22-7832-14), p16-27

Cc: [email protected]
Signed-off-by: Eric Farman <[email protected]>
Acked-by: Christian Borntraeger <[email protected]>
Reviewed-by: Farhan Ali <[email protected]>
Signed-off-by: Christian Borntraeger <[email protected]>
Message-ID: <[email protected]>
Signed-off-by: Cornelia Huck <[email protected]>
(cherry picked from commit 33bece0fa1)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-15 12:56:43 +03:00
Christian Borntraeger adc0ac7c3b s390x/sclpcpi: check event length field before reading from buffer
A guest might send a too short SCCB with SCLP_EVENT_CTRL_PGM_ID. QEMU
would fill its data structures with garbage data. Check for the precise
length of the CBI data structure and reject otherwise.

Fixes: f345978f24 ("hw/s390x: add Control-Program Identification to QOM")
Cc: [email protected]
Signed-off-by: Christian Borntraeger <[email protected]>
Reviewed-by: Matthew Rosato <[email protected]>
Reviewed-by: Janosch Frank <[email protected]>
Reviewed-by: Eric Farman <[email protected]>
Message-ID: <[email protected]>
Signed-off-by: Cornelia Huck <[email protected]>
(cherry picked from commit 8a116a2853)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-15 12:15:53 +03:00
Christian Borntraeger f0777ba872 s390x/sclp: prevent re-reading the sclp header
We verify the sccb length and then allocate based on that length. The
following access re-reads the sccb again. This can race against other
vCPUs overwriting the length field.

sclp_service_call_protected does not need a change as the ultravisor
provides a consistent snapshot.

Fixes: c1db53a591 ("s390/sclp: read sccb from mem based on provided length")
Cc: [email protected]
Signed-off-by: Christian Borntraeger <[email protected]>
Reviewed-by: Matthew Rosato <[email protected]>
Reviewed-by: Eric Farman <[email protected]>
Reviewed-by: Collin Walling <[email protected]>
Message-ID: <[email protected]>
Signed-off-by: Cornelia Huck <[email protected]>
(cherry picked from commit 20701190e0)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-15 12:15:53 +03:00
Peter Maydell ab8a4c1145 hw/misc/stm32_rcc: Correct offset-to-irq calculation
In the STM32 RCC, there is a block of 5 "enable" registers, each of
which has 32 bits; each bit determines the level of one of the 5 * 32
= 160 enable_irq output lines.  The code calculates the irq to be
worked on using
  irq_offset = ((addr - STM32_RCC_AHB1_ENR) / 4) * 32;

This assumes that the registers are all consecutive; however, there
is a gap between the AHB1/2/3 registers and the APB1/2 registers, so
for the APB1/2 registers we calculate a number that is 32 too high
and can index off the end of the enable_irq[] array.

The handling of the reset registers has an identical bug.

Adjust the calculation of irq_offset to cope with the gap, and fix
the case labels so accesses to the gap fall into the default
LOG_UNIMP rather than being treated as if they were an actual
register.

Coverity CID: 1663683, 1663686
Cc: [email protected]
Signed-off-by: Peter Maydell <[email protected]>
Reviewed-by: Alistair Francis <[email protected]>
Message-id: [email protected]
(cherry picked from commit 3c27494434)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-14 23:47:48 +03:00
Peter Maydell 3a728dde5d hw/display/sm501: Don't allow guest to set ram size larger than it is
The SM501 DRAM_CONTROL register has a 7 bit Size field which allows
the guest to change the local memory size.  We use the local memory
size in bounds checks calculations for 2D operations. Currently we
have no check on the validity of the value the guest programs to
this field, which means that the guest can:
 - set it to a reserved value (6 or 7) which will cause
   get_local_mem_size() to read outside sm501_mem_local_size[]
 - set it to a value corresponding to more RAM than the card
   was created with, so that the 2D bounds check will let 2D
   operations access off the end of the memory region

Fix this by decoupling the value the guest reads and writes to this
field from the internal size we consider the local memory to have.
We validate changes and ignore them except for readback if they would
be reserved values or values for more memory than the card has.

Cc: [email protected]
Reported-by: Heechan Kang
Tested-by: BALATON Zoltan <[email protected]>
Reviewed-by: BALATON Zoltan <[email protected]>
Signed-off-by: Peter Maydell <[email protected]>
Message-id: [email protected]
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3811
Signed-off-by: Peter Maydell <[email protected]>
(cherry picked from commit 2ac2cf0483)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-14 23:47:33 +03:00
Peter Maydell c597c1c76a hw/display/sm501: Avoid overflow problems in bounds check calculations
When we check that a 2D rectangle operation isn't going to run off
the end of video RAM, we do the calculations as 32 bit arithmetic.
This means that carefully chosen guest register values can cause an
overflow so we don't detect that the operation is going to go outside
video memory.

Abstract the check out into a function, do the calculations as
64-bit arithmetic, and add assertions about the ranges of the
inputs.

Cc: [email protected]
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3584
Signed-off-by: Peter Maydell <[email protected]>
Tested-by: BALATON Zoltan <[email protected]>
Reviewed-by: BALATON Zoltan <[email protected]>
Message-id: [email protected]
(cherry picked from commit 422734d5fc)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-14 23:47:19 +03:00
Peter Maydell e68642b206 hw/display/sm501: Catch bad coordinates for RTL operations
The sm501 code doesn't check whether a right-to-left operation has
specified a width greater than the x-coordinate (which would make it
extend off the left edge of the screen), or similarly a height
greater than the y-coordinate.  This means the guest can misprogram
the device so that we underflow when calculating the address of the
top left pixel, which might result in accessing out of bounds
memory.  Catch this as a guest error and ignore the operation.

Reported-by: Yannick Wang
Tested-by: BALATON Zoltan <[email protected]>
Reviewed-by: BALATON Zoltan <[email protected]>
Signed-off-by: Peter Maydell <[email protected]>
Message-id: [email protected]
Cc: [email protected]
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3920
Signed-off-by: Peter Maydell <[email protected]>
(cherry picked from commit b378a1bd86)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-14 23:47:11 +03:00
Peter Maydell 758d4cdb27 hw/usb/dev-wacom: Don't write off end of buffer
In usb_wacom_handle_data() we allocate a buffer with a size
determined by the transfer size requested by the guest.  We then fill
it in by calling either usb_mouse_poll() or usb_wacom_poll(), both of
which functions take a length and return an actual length, which we
pass to usb_packet_copy().  However, usb_mouse_poll() doesn't check
the buffer size as it fills in the buffer, so if the guest passes an
overly short transfer size then it will write off the end of the
allocated buffer.

Check the length is at least big enough for the minimum 3 byte
packet and return nothing if it is not, as usb_wacom_poll() does.

Cc: [email protected]
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3672
Signed-off-by: Peter Maydell <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Message-id: [email protected]
(cherry picked from commit 2c6fae7d7d)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-14 23:47:00 +03:00
Peter Maydell a615c57208 hw/net/vmxnet3: Correct bounds check on tx queue index
In vmxnet3_io_bar0_write(), we try to bounds-check the TX queue index
provided by the guest against the total number of queues.  However,
we have an off-by-one error: the valid indexes are from 0 to
txq_num-1, so we need a "<" comparison, not "<=".

Cc: [email protected]
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3780
Signed-off-by: Peter Maydell <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Message-id: [email protected]
(cherry picked from commit 4571c79c57)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-14 23:46:49 +03:00
Richard Henderson a1c61f9328 target/arm: Be more defensive for invalid tlbi_aa64_get_range
It's possible to program TCR_ELx with an invalid granule size,
which could match passing an invalid granule size to TLBI RVA,
which would then fall through to assert in arm_granule_bits.

Cc: [email protected]
Fixes: 3c003f7029 ("target/arm: Use ARMGranuleSize in ARMVAParameters")
Signed-off-by: Richard Henderson <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Message-id: [email protected]
Signed-off-by: Peter Maydell <[email protected]>
(cherry picked from commit 79cabc6cb7)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-14 23:46:32 +03:00
Peter Maydell 64226416c6 linux-user: Validate guest-passed dm_ioctl data_size
In do_ioctl_dm() we work with a struct dm_ioctl from the guest.  This
has a fixed initial part, and then a variable data part; the guest
tells us how long that part is by setting the data_size field.  The
data_size is supposed to include the length of the fixed parts of the
struct dm_ioctl.  Currently we don't validate anything about the
guest-provided data_size, and we use it to allocate a buffer which we
then copy the fixed part of the dm_ioctl struct into.  This means
that if the guest passes a very small data_size the copy of the fixed
part will overrun the buffer.

Perform the same sanitizing of the minimum and maximum limits of the
data_size that the kernel does in drivers/md/dm-ioctl.c in the
copy_params() function.

Cc: [email protected]
Fixes: 56e904ecb2 ("linux-user: implement device mapper ioctls")
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3736
Signed-off-by: Peter Maydell <[email protected]>
Reviewed-by: Helge Deller <[email protected]>
Signed-off-by: Helge Deller <[email protected]>
(cherry picked from commit a47e3c26b1)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-14 22:59:37 +03:00
Heinrich Schuchardt 6c586f357e tests: update SPCR loongarch64 and riscv64 test data
On LoongArch and RISC-V the SPCR test data contained:

    Terminal Type : 00
    Language : 03

The corrected values are:

    Terminal Type : 03
    Language : 00

See the specification of the table in
https://learn.microsoft.com/en-us/windows-hardware/drivers/bringup/serial-port-console-redirection-table

The ACPI table data was rebuilt with
tests/data/acpi/rebuild-expected-aml.sh.

Remove SPCR expections from tests/qtest/bios-tables-test-allowed-diff.h.

Signed-off-by: Heinrich Schuchardt <[email protected]>
Acked-by: Alistair Francis <[email protected]>
Message-ID: <[email protected]>
Signed-off-by: Alistair Francis <[email protected]>
(cherry picked from commit ec7d324287)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-11 09:52:33 +03:00
Heinrich Schuchardt 695018a606 hw/acpi: correct field sequence in SPCR table
On LoongArch and RISC-V invalid SPCR tables are created:

    Terminal Type : 00
    Language : 03

The correct values are:

    Terminal Type : 03
    Language : 00

This is due to commit 7dd0b070fa ("hw/arm/virt-acpi-build.c: Migrate
SPCR creation to common location") that swapped the fields.

See the specification of the table in
https://learn.microsoft.com/en-us/windows-hardware/drivers/bringup/serial-port-console-redirection-table

This page shows version 1.10. But the sequence of the fields was not changed
since version 1.0.

Our LoongArch and ARM code uses version 1.07 of the specification.
Our RISC-V code uses version 1.10 of the specification.

Fixes: 7dd0b070fa ("hw/arm/virt-acpi-build.c: Migrate SPCR creation to common location")
Origin: https://lore.kernel.org/qemu-devel/[email protected]/T/#u
Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/qemu/+bug/2146419
Signed-off-by: Heinrich Schuchardt <[email protected]>
Reviewed-by: Alistair Francis <[email protected]>
Message-ID: <[email protected]>
Signed-off-by: Alistair Francis <[email protected]>
(cherry picked from commit 15c73b0f17)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-11 09:52:22 +03:00
Heinrich Schuchardt 9899e0f351 tests: allow differences in SPCR
For easier bisection add the SPCR table to bios-tables-test-allowed-diff.h.

Signed-off-by: Heinrich Schuchardt <[email protected]>
Acked-by: Alistair Francis <[email protected]>
Message-ID: <[email protected]>
Signed-off-by: Alistair Francis <[email protected]>
(cherry picked from commit 18a5220990)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-11 09:52:11 +03:00
Alistair Francis 9156f2b958 hw/pci/pcie_doe: Check mailbox length for overflows
It was possible that a guest could overflow the `doe_cap->write_mbox`
buffer by writing more then PCI_DOE_DW_SIZE_MAX dwords.
`doe_cap->write_mbox_len` would continue to increment and there were no
bounds checks on the length when offsetting into doe_cap->write_mbox.

This patch adds a check and reports a guest error if we would overflow.

On an overflow we also silenty discard the entire object as instructed
to do in the PCIe spec when the length specified in the header
(up to PCI_DOE_DW_SIZE_MAX dwords) doesn't match the length of the
object.

Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3679
Signed-off-by: Alistair Francis <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Reviewed-by: Tao Tang <[email protected]>
Message-ID: <[email protected]>
Signed-off-by: Alistair Francis <[email protected]>
(cherry picked from commit c7e6185454)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-11 09:49:36 +03:00
Daniel Henrique Barboza 3fc9112985 hw/riscv/riscv-iommu.c: set ftype and iova in riscv_iommu_ctx()
We're hardcoding faulting type as READ, where it could very well be a
write access, and we're not recording the faulting addr/iova.

A note was added in the fault_type logic because I wasn't able to
trivially handle a probable code repeitition it in this same patch.
Something to do in a later date.

Fixes: 0c54acb824 ("hw/riscv: add RISC-V IOMMU base emulation")
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3564
Signed-off-by: Daniel Henrique Barboza <[email protected]>
Message-ID: <[email protected]>
Signed-off-by: Alistair Francis <[email protected]>
(cherry picked from commit ce7fb32827)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-11 09:46:29 +03:00
Chengbo Gao 49e8463e6c hw/riscv/riscv-iommu: Avoid caching PCI device IDs
PCI bus numbers may still be unassigned when QEMU initializes a PCI
device's bus-master address space.  For devices behind bridges,
pci_bus_num() can return 0 at that point because the guest has not yet
programmed the bridge Secondary Bus Number register.

The RISC-V IOMMU currently stores a fixed device_id in RISCVIOMMUSpace
when the address space is created.  If the guest later enumerates the
device on a non-zero bus, DMA translation still uses the stale device_id
and may look up the wrong device context in the DDT.

Store the stable PCIBus pointer and devfn in RISCVIOMMUSpace instead,
and compute the device_id from the current bus number when it is needed.
This keeps DMA translation and ATS invalidation in sync with guest PCI
bus enumeration.

Signed-off-by: Chengbo Gao <[email protected]>
Reviewed-by: Daniel Henrique Barboza <[email protected]>
Message-ID: <[email protected]>
Signed-off-by: Alistair Francis <[email protected]>
(cherry picked from commit ca7bac51e0)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-11 09:46:20 +03:00
Daniel Henrique Barboza a6b0351853 hw/riscv/riscv-iommu: forbid GATE/SADE if caps.AMO_HWADD is zero
When capabilities.AMO_HWADD isn't set, DC.tc.GADE and DC.tc.SADE are
reserved bits and setting them throws a DDT_MISCONFIGURED error.

Fixes: 0c54acb824 ("hw/riscv: add RISC-V IOMMU base emulation")
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3549
Signed-off-by: Daniel Henrique Barboza <[email protected]>
Reviewed-by: Nutty Liu <[email protected]>
Message-ID: <[email protected]>
Signed-off-by: Alistair Francis <[email protected]>
(cherry picked from commit 6d2b9d542f)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-11 09:44:37 +03:00
Daniel Henrique Barboza 2e8fa5ed86 hw/riscv/riscv-iommu.c: update ioval2 when faulting in spa_fetch()
riscv_iommu_translate(), the only caller of riscv_iommu_spa_fetch(),
will use riscv_iommu_report_fault() for all faults it detects.  And it
will use iotlb->translated_addr as 'iotval2' every time.

At this moment we're updating iotlb->translated_addr only after a
translation step is completed, meaning any fault that occur before that
will have a zeroed iotlb->translated_addr, and as a result iotval2 will
also be zero later on.

Keep iotlb->translated_addr updated with the latest translated addr we
have.

Fixes: 0c54acb824 ("hw/riscv: add RISC-V IOMMU base emulation")
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3559
Signed-off-by: Daniel Henrique Barboza <[email protected]>
Acked-by: Alistair Francis <[email protected]>
Message-ID: <[email protected]>
Signed-off-by: Alistair Francis <[email protected]>
(cherry picked from commit 79616dd6e4)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-11 09:44:29 +03:00
Daniel Henrique Barboza 4f5e2c7715 hw/riscv/riscv-iommu.c: check for misaligned IOHGATP_PPN
We must check if IOHGATP_PPN is 16kb aligned for non-bare GATP modes.

Fixes: 69a9ae4836 ("hw/riscv/riscv-iommu: add ATS support")
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3550
Signed-off-by: Daniel Henrique Barboza <[email protected]>
Reviewed-by: Chao Liu <[email protected]>
Reviewed-by: Nutty Liu <[email protected]>
Message-ID: <[email protected]>
Signed-off-by: Alistair Francis <[email protected]>
(cherry picked from commit bf274c5429)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-11 09:44:14 +03:00
Daniel Henrique Barboza 79e21b2fab hw/riscv/riscv-iommu-sys.c: record fault on IOMMU-generated MSI write
The riscv-iommu spec requires that the IOMMU records its own generated
MSI write faults.

Fixes: 01c1caa9d1 ("hw/riscv/virt.c, riscv-iommu-sys.c: add MSIx support")
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3572
Signed-off-by: Daniel Henrique Barboza <[email protected]>
Reviewed-by: Nutty Liu <[email protected]>
Message-ID: <[email protected]>
Signed-off-by: Alistair Francis <[email protected]>
(cherry picked from commit 58e801f74e)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-11 09:41:46 +03:00
Daniel Henrique Barboza d05327400f hw/riscv/riscv-iommu.c: check reserved MSI PTE basic bits
We need to throw an MSI_MISCONFIGURED error when any of the reserved PTE
bits (first doubleword only) are set.

Fixes: Fixes: 0c54acb824 ("hw/riscv: add RISC-V IOMMU base emulation")
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3563
Signed-off-by: Daniel Henrique Barboza <[email protected]>
Reviewed-by: Nutty Liu <[email protected]>
Message-ID: <[email protected]>
Signed-off-by: Alistair Francis <[email protected]>
(cherry picked from commit 11486349ad)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-11 09:41:37 +03:00
Daniel Henrique Barboza 3dfa835d44 hw/riscv/riscv-iommu.c: fault for non-user PTE in G_STAGE
riscv-iommu spec 1.0 says:

"When checking the U bit in a second-stage PTE, the transaction
 is treated as not requesting supervisor privilege."

We need to *always* fault in case we're on G_STAGE and PTE_U is cleared
since we can't be on supervisor mode at this point.

Fixes: 0c54acb824 ("hw/riscv: add RISC-V IOMMU base emulation")
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3555
Signed-off-by: Daniel Henrique Barboza <[email protected]>
Message-ID: <[email protected]>
Signed-off-by: Alistair Francis <[email protected]>
(cherry picked from commit 9158c900ab)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-11 09:41:29 +03:00
Daniel Henrique Barboza ca4a88e4ae hw/riscv/riscv-iommu.c: fault when !PTE_U and no priv access
All IOMMU accesses are assumed to be user mode unless told otherwise,
i.e. we have a process_id.  In case we have a non-user mode leaf PTE
(PTE_U isn't set) and we are running in user mode, we need to throw a
fault.

This also reflects on qos-riscv-iommu tests: the tests always run in
user mode so our PTEs must have PTE_U (bit 0x10) set.

Fixes: 0c54acb824 ("hw/riscv: add RISC-V IOMMU base emulation")
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3553
Signed-off-by: Daniel Henrique Barboza <[email protected]>
Reviewed-by: Nutty Liu <[email protected]>
Reviewed-by: Chao Liu <[email protected]>
Message-ID: <[email protected]>
Signed-off-by: Alistair Francis <[email protected]>
(cherry picked from commit b795ea0ba4)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-11 09:34:28 +03:00
Daniel Henrique Barboza 76edd81944 hw/riscv/riscv-iommu.c: check for reserved PTE bits
We need to fault if reserved PTE bits (60:54) are set.

Fixes: 0c54acb824 ("hw/riscv: add RISC-V IOMMU base emulation")
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3554
Signed-off-by: Daniel Henrique Barboza <[email protected]>
Reviewed-by: Nutty Liu <[email protected]>
Reviewed-by: Chao Liu <[email protected]>
Message-ID: <[email protected]>
Signed-off-by: Alistair Francis <[email protected]>
(cherry picked from commit c1d5ec3a2f)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-11 09:34:17 +03:00
Daniel Henrique Barboza f6f4d1a187 hw/riscv/riscv-iommu.c: fix fault type for spa_fetch() faults
Under certain circunstances, like the one described in [1] and [2],
a read operation that faults will be logged as a write fault instead,
and vice-versa, if they happen after the translation phase in
riscv_iommu_spa_fetch().

The first problem is that we're overwriting iotlb->perm with PTE flags,
so an IOMMU_RO access flag can be overwritten by whatever flags
the PTE has.  This will cause the wrong fault type to be thrown at
the end of the function in case a fault happens.

To solve the iotlb->perm overwrite we'll bit_and the original
iotlb->perm access flags with the PTE access flags, preserving the
original access type.  So a IOMMU_RO access in a R+W PTE will result in
a IOMMU_RO perm.

Second, the resulting fault is received by riscv_iommu_translate(), which
will then report the fault.  To do that we require a transaction type
(ttype).  We're prioritizing checking "perm & IOMMU_RW" to set a
UADDR_WR ttype, and then checking "perm & IOMMU_RO" to set UADDR_RD
ttype.  The issue with that is IOMMU_RO=1 and IOMMU_RW=3, thus checking
"perm & IOMMU_RW" for a write then "perm & IOMMU_RO" for a read will
cause the read fault to always be diagnosed as write.

Make the iotlb->perm matches more strict: "perm & IOMMU_RW" must be
exactly IOMMU_RW, ensuring that 'perm' has both flags.  Then we can
check perm & IOMMU_WO and perm & IOMMU_RO without worrying about
overlapping with the RW flag.

[1] https://gitlab.com/qemu-project/qemu/-/work_items/3557
[2] https://gitlab.com/qemu-project/qemu/-/work_items/3577

Fixes: 69a9ae4836 ("hw/riscv/riscv-iommu: add ATS support")
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3557
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3577
Signed-off-by: Daniel Henrique Barboza <[email protected]>
Acked-by: Alistair Francis <[email protected]>
Message-ID: <[email protected]>
Signed-off-by: Alistair Francis <[email protected]>
(cherry picked from commit b18e3f0e2d)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-11 09:33:42 +03:00
Jia Jia a90c092011 hw/ufs: avoid double unref of wrapped scsi-hd
ufs_init_scsi_device() creates an internal scsi-hd and adds it as a
child of lu->bus. qdev_realize_and_unref() then drops the construction
reference, leaving the bus child ownership to tear it down.

ufs_lu_unrealize() still unrefs lu->scsi_dev directly. If the UFS
controller is ejected through ACPI PCI hotplug, the scsi-hd object can be
finalized there and then the bus child removal RCU callback later unrefs
the same object again.

Keep lu->scsi_dev as a borrowed pointer and clear it during unrealize
without unreffing it.

Add a qtest that ejects the UFS controller through the x86 ACPI PCI
hotplug eject register. On an ASAN build, the test reproduces the UAF
before the fix.

Fixes: 096434fea1 ("hw/ufs: Modify lu.c to share codes with SCSI subsystem")
Cc: [email protected]
Signed-off-by: Jia Jia <[email protected]>
Signed-off-by: Jeuk Kim <[email protected]>
(cherry picked from commit 90aacd5bc4)
(Mjt: tests/qtest/ufs-test.c: context fixup)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-10 13:41:08 +03:00
yujun 94f798317d crypto/x509-utils: fix gnutls error code in crt_init failure path
qcrypto_get_x509_cert_fingerprint() reports gnutls_strerror(ret) when
gnutls_x509_crt_init() fails, but ret is still the initial value -1.
Store the gnutls return code before formatting the error, matching
other gnutls call sites in the tree.

Fixes: 2183ab6251 ("crypto/x509-utils: Check for error from gnutls_x509_crt_init()")
Signed-off-by: yujun <[email protected]>
Reviewed-by: Daniel P. Berrangé <[email protected]>
Signed-off-by: Daniel P. Berrangé <[email protected]>
(cherry picked from commit 4952681a5f)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-10 13:36:09 +03:00
Randy Schifflin f6427df175 target/sh4: fixup tcg for sh4 fipr/ftrv instructions
Fixes TCG generation for sh4 `fipr` and `ftrv` instructions.
Updates the current logic for these instructions to check the
FPSCR register appropriately (according to the sh4 cpu manual, `fipr`
and `ftrv` are only defined when the FPSCR register PR flag is 0).
Also fixes the mth/nth-vector operands by multiplying by 4 to convert
to the correct floating point register offset.

Signed-off-by: Randy Schifflin <[email protected]>
Reviewed-by: Yoshinori Sato <[email protected]>
Message-ID: <20260629-fixup-sh4-tcg-fpu-instructions-b4-v1-2-4356b305f971@gmail.com>
Signed-off-by: Philippe Mathieu-Daudé <[email protected]>
(cherry picked from commit 614a52cf54)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-09 08:58:04 +03:00
Richard Henderson ca7bfa27b7 tcg/loongarch64: Fix cmp_vec with TCG_COND_NE
For NE we need to invert EQ, not swap operands.

Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3589
Signed-off-by: Richard Henderson <[email protected]>
Message-ID: <[email protected]>
(cherry picked from commit c56ebd64b8)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-09 08:45:23 +03:00
Ilya Leoshkevich 3b0195a919 accel/tcg: Make PageFlagsNodes' start and last immutable
page_check_range() may race with pageflags_set_clear() as follows:

    T1                                     T2
    -------------------------------------  --------------------------------
                                           p = pageflags_find(start, last);
    interval_tree_remove(&p->itree, ...);
    p->itree.start = last + 1;
                                           if (start < p->itree.start) {
                                               ret = false;
    interval_tree_insert(&p->itree, ...);

leading to errors like

    fail indirect write 0x72f0a659aff0 (Bad address)

in vma-pthread test. I am able to reliably reproduce this on a machine
with 32 SMT threads as follows in about 25 seconds:

    jobs=32; \
    seq "$jobs" | \
        time -p parallel \
            --jobs="$jobs" \
            --halt=now,done=1 \
            --ungroup \
            '
                _={};
                while ./qemu-s390x tests/tcg/s390x-linux-user/vma-pthread; do
                    printf .;
                done
            '

Also wasmtime project reported a similar failure pattern in their CI [1]
with a similar reproducer [2].

There are other races like this. In general, region bounds mutating
underneath the reader are very hard to reason about. So fix this by
preventing mutations and creating copies instead. Use RCU guards in
readers to avoid uses-after-frees.

Now, when the reader finds a node, it may fearlessly access its fields
and be certain that at some point in time the respective region had the
respective bounds and permissions. The downside is slightly more
expensive mprotect(), but complexity reduction is worth it.

Lockless field accesses should probably be wrapped in qatomic_read(),
but this is a pre-existing issue, so do not change it here.

[1] https://github.com/bytecodealliance/wasmtime/issues/10000
[2] https://gist.github.com/alexcrichton/f14f23a892ffb9df2522754572d51b1c

Cc: [email protected]
Reported-by: Alex Crichton <[email protected]>
Reported-by: Ulrich Weigand <[email protected]>
Fixes: 67ff2186b0 ("accel/tcg: Use interval tree for user-only page tracking")
Signed-off-by: Ilya Leoshkevich <[email protected]>
Reviewed-by: Richard Henderson <[email protected]>
Reviewed-by: Pierrick Bouvier <[email protected]>
Signed-off-by: Richard Henderson <[email protected]>
Message-ID: <[email protected]>
(cherry picked from commit e03b7dac65)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-09 08:29:21 +03:00
Richard Henderson 497273cecf accel/tcg: Use TLB_FORCE_SLOW not TLB_MMIO for user-only plugins
In 6d03226b42 we set TLB_MMIO to a non-zero value for user-only
so that we could return a non-zero value from probe_* functions
so that we could force callers like Arm SVE vector moves to use
the slow path rather than direct access.  All for the sake of
exposing these accesses to plugins.

Back then, TLB_FORCE_SLOW did not exist, so TLB_MMIO seemed like
a reasonable solution.  However, user-only doesn't really have
MMIO and this has knock-on effects, like forcing Arm SVE first-fault
vector loads to stop.  Better to use TLB_FORCE_SLOW as a more exact
trigger for plugins.

Cc: [email protected]
Fixes: 6d03226b42 ("plugins: force slow path when plugins instrument memory ops")
Acked-by: Alex Bennée <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Signed-off-by: Richard Henderson <[email protected]>
Message-ID: <[email protected]>
(cherry picked from commit b79a9b6e5b)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-09 06:57:03 +03:00
Sanjeeva Yerrapureddy 95abfb8549 hw/net: fix e1000e/igb ip_len inflation by Ethernet minimum-frame padding
When a guest transmits a short Ethernet frame, iov_size() returns the
padded wire length including any bytes added to reach the Ethernet
minimum frame size of 60 bytes.  net_tx_pkt_rebuild_payload() uses
this inflated size as payload_len.  net_tx_pkt_update_ip_hdr_checksum()
then overwrites the IPv4 Total Length field with payload_len +
l3_hdr_len, inflating it by the padding.  The receiver interprets
Ethernet padding as IP payload, producing a malformed packet.

Fix by removing the ip_len write from net_tx_pkt_update_ip_hdr_checksum()
so it only recomputes the checksum, and moving the ip_len assignment
into net_tx_pkt_update_ip_checksums() where it is only performed for
TSO (where ip_len must be derived from payload_len since the guest sets
ip_len=0 per Intel 82574 datasheet §7.3.4 for super-packets the host
will segment).

Both e1000e and igb already call net_tx_pkt_update_ip_hdr_checksum()
from their IXSM paths, so both are corrected by this single common-
layer change.

Signed-off-by: Sanjeeva Yerrapureddy <[email protected]>
Reivewed-by: Akihiko Odaki <[email protected].i.u-tokyo.ac.jp>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Message-ID: <20260629-net-tx-pkt-ip-length-padding-v5-1-16760e30252e@gmail.com>
Signed-off-by: Philippe Mathieu-Daudé <[email protected]>
(cherry picked from commit 9e41b5d22a)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-08 15:41:42 +03:00
Stefan Hajnoczi 794e1c85fb scsi: register again after PREEMPT without reservation
The SCSI specification says PREEMPT without a reservation removes all
registrations with the given key. Try to register again after PREEMPT
since our key will have been removed.

In practice some SCSI targets keep the calling I_T nexus' registration
instead of removing it. Therefore we need to handle both the
spec-compliant and the non-compliant behavior.

Signed-off-by: Stefan Hajnoczi <[email protected]>
Reviewed-by: Paolo Bonzini <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Paolo Bonzini <[email protected]>
(cherry picked from commit b9a3b329d0)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-08 13:01:49 +03:00
Stefan Hajnoczi 2ff4a9cacd scsi: always send valid PREEMPT TYPE field
The SPC-6 specification says that the PREEMPT service action ignores the
TYPE field when there is no reservation. However, the LIO Linux iSCSI
target rejects commands with a zero TYPE field. The field never ends up
being used in this case, so replace it with a "valid" value to work
around the issue.

Reported-by: Qing Wang <[email protected]>
Buglink: https://redhat.atlassian.net/browse/RHEL-155807
Signed-off-by: Stefan Hajnoczi <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Paolo Bonzini <[email protected]>
(cherry picked from commit 15a202656c)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-08 13:01:49 +03:00
Stefan Hajnoczi 802316b77f scsi: adjust error_prepend() formatting
The error strings will be concatenated so add a separator to make the
combined error message easy to read.

Signed-off-by: Stefan Hajnoczi <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Paolo Bonzini <[email protected]>
(cherry picked from commit 15c57ac351)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-08 13:01:49 +03:00
hemanshu.khilari.foss ca92663d7a hw/core/qdev-clock: Fix potential null pointer dereference
qdev_get_clocklist() function returns a pointer to the NamedClockList
struct. This function is called in qdev_alias_clock() and the returned
pointer is immediately dereferenced without a null check.

Passing a clock name that doesn't exist to qdev_get_clocklist() is a
programming error, and so this change is not fixing a bug, only making
the reporting of that programming error a bit more helpful and bringing
it in to line with qdev_get_clock_in() and qdev_get_clock_out().

Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/2342
Signed-off-by: hemanshu.khilari.foss <[email protected]>
Message-id: [email protected]
Reviewed-by: Luc Michel <[email protected]>
Reviewed-by: Peter Maydell <[email protected]>
Signed-off-by: Peter Maydell <[email protected]>
(cherry picked from commit 7913b3b946)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-08 13:01:49 +03:00
Nathan Chen e42263941e hw/arm/smmuv3: Update ATC invalidation check
Use smmuv3_ats_enabled() to determine whether ATS is enabled for the
guest when handling an ATC invalidation command, as setting the ATS
property value to 'auto' will resolve to ATS being detected as
enabled in the ATC invalidation check otherwise.

Fixes: f7f5013a55 ("hw/arm/smmuv3-accel: Add support for ATS")
Reported-by: Shameer Kolothum <[email protected]>
Reviewed-by: Eric Auger <[email protected]>
Reviewed-by: Shameer Kolothum <[email protected]>
Signed-off-by: Nathan Chen <[email protected]>
Tested-by: Eric Auger <[email protected]>
Message-id: [email protected]
Signed-off-by: Peter Maydell <[email protected]>
(cherry picked from commit 8addbdb793)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-08 13:01:49 +03:00
lizhaoxin04 8e546d82c9 vdpa: fix use-after-free of vqs in vhost_vdpa_device_unrealize
vhost_vdpa_device_unrealize() frees s->dev.vqs before
vhost_dev_cleanup(), but vhost_dev_cleanup() still accesses hdev->vqs
while tearing down virtqueues. This leads to a use-after-free and may
crash QEMU with SIGSEGV during vDPA hot-unplug.

Save the vqs pointer in a local variable, call vhost_dev_cleanup(),
and free it afterward. This matches the cleanup pattern used by
vhost-scsi.

Fixes: b430a2bd23 ("vdpa: add vdpa-dev support")
Co-developed-by: Miao Kezhan <[email protected]>
Signed-off-by: Li Zhaoxin <[email protected]>
Reviewed-by: Michael S. Tsirkin <[email protected]>
Signed-off-by: Michael S. Tsirkin <[email protected]>
Message-ID: <[email protected]>
(cherry picked from commit e03463812e)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-08 13:01:49 +03:00
no92 1a1ab5c233 intel_iommu: Correctly set pt bit in extended capability register
With the changes in c7b2e22bd9, the `pt` bit was set in the (wrong)
capability register, instead of the (correct) extended capability
register.

Fixes: c7b2e22bd9 ("hw/i386/x86-iommu: Remove X86IOMMUState::pt_supported field")
Signed-off-by: no92 <[email protected]>
Reviewed-by: Clement Mathieu--Drif <[email protected]>
Reviewed-by: Yi Liu <[email protected]>
Reviewed-by: Michael S. Tsirkin <[email protected]>
Signed-off-by: Michael S. Tsirkin <[email protected]>
Message-ID: <[email protected]>
(cherry picked from commit dbc0ed5622)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-08 13:01:49 +03:00
Thomas Huth 2cd92501d8 hw/display/qxl: Fix mono cursor validation that can read past a cursor chunk
qxl_render_cursor() maps the guest-provided QXLCursor object using the
guest-controlled cursor->chunk.data_size.
For a mono cursor, qxl_cursor() then validates the expected bitmap size
against cursor->data_size, but it does not validate that the first chunk
actually contains that many bytes.
A guest could set cursor->data_size to the correct full mono cursor size
while setting cursor->chunk.data_size to zero. In that case, cursor_set_mono()
reads the AND/XOR masks starting at cursor->chunk.data. If the cursor object
is placed at the end of the QXL RAM BAR, those reads cross the mapped RAM
region and could crash the QEMU process (e.g. under ASan).

Fix it by double-checking cursor->chunk.data_size for the correct size.

This patch is based on the suggested changes by the reporter in the bug
ticket.

Reported-by: huntr bubble
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3646
Signed-off-by: Thomas Huth <[email protected]>
Acked-by: Marc-André Lureau <[email protected]>
Message-ID: <[email protected]>
Signed-off-by: Philippe Mathieu-Daudé <[email protected]>
(cherry picked from commit 0e51b71c7b)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-08 13:01:49 +03:00
Peter Maydell 7ec5e3141e hw/scsi/mptsas: Reset doorbell state on reset
Currently the mptsas reset function clears intr_status, but it
doesn't reset the doorbell state machine.  This means that the state
machine and the interrupt state get out of sync, and the guest can
trigger an assertion failure in mptsas_doorbell_read() where
s->doorbell_state is still DOORBELL_READ but s->intr_status does not
have MPI_HIS_DOORBELL_INTERRUPT set.

Fix this by having reset also reset the doorbell state.  Strictly
speaking we don't need to also clear doorbell_reply_idx and
doorbell_reply_size, because those are only read when in
DOORBELL_READ state, and the code always sets them up before
transitioning into that state.  But it's less confusing to clear them
out on reset.

Cc: [email protected]
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/304
Signed-off-by: Peter Maydell <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Message-ID: <[email protected]>
Signed-off-by: Philippe Mathieu-Daudé <[email protected]>
(cherry picked from commit 831a13665a)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-08 13:01:49 +03:00
Peter Maydell f6415f583a hw/dma/i8257: Return zeroes for read_memory in verify mode
The i8257 DMA controller has a "verify" mode, which the datasheet
describes like this:

> DMA verify, which does not actually involve the transfer of data.
> When an 8257 channel is in the DMA verify mode, it will respond the
> same as described for transfer operations, except that no memory or
> I/O read/write control signals will be generated.  When an 8257
> channel is in the DMA verify mode, it will respond the same as
> described for transfer operations, except that no memory or I/O read
> /write control signals will be generated, thus preventing the
> transfer of data.  The 8257, however, will gain control of the system
> bus and will acknowledge the peripheral's DMA request for each DMA
> cycle.  The perihperal can use these acknowledge signals to enable an
> internal access of each byte of a data block in order to execute some
> verification procedure, such as the accumulation of a CRC check word.

In practice, for QEMU's purposes the only real user of this is the
floppy controller, which can be made to perform a "read data from
floppy disk and check the checksum" by telling the fdc to do a read
and the DMA controller to do a verify.  This causes the fdc to do all
the usual read actions including the checksum, but the data is never
written to memory.  However, it is possible for a guest doing
something silly to program the DMA controller to do a verify
operation for a device that wants to read from memory.  Currently we
simply return early from i8257_dma_read_memory() without writing to
the buffer.  None of the callers (the GUS, sb16 and cs4231a sound
cards, plus the fdc) expect this, so they will take the uninitialized
data as if it were from the guest.  This can cause us to leak host
data off the stack into the guest.

Make i8257_dma_read_memory() fill the buffer with zeroes rather
than leaving it untouched for a verify operation.

Cc: [email protected]
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3487
Signed-off-by: Peter Maydell <[email protected]>
Reviewed-by: Daniel P. Berrangé <[email protected]>
Message-ID: <[email protected]>
Signed-off-by: Philippe Mathieu-Daudé <[email protected]>
(cherry picked from commit 03071f99a3)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-08 13:01:49 +03:00
Denis V. Lunev 8a0f9ce3b3 tests/qtest/ahci: test ATAPI read completing after engine restart
Add a regression test for the crash that occurs when a buffered ATAPI
read completes after the command engine has been restarted. Issue an
ATAPI READ_10 against a blkdebug-backed CD, suspend the backend read so
it stays in flight, stop and restart the port's command engine (which
re-maps the command list and clears cur_cmd), then release the read.

The PIO and DMA reply paths fault in different AHCI helpers
(ahci_pio_transfer() vs ahci_dma_rw_buf()), so cover both. The DMA
variant is the reliable guard: on engine restart check_cmd() can re-arm
cur_cmd before the old read completes, so the PIO variant does not fault
in every build.

The test only asserts that qemu survives a subsequent register access;
if the blkdebug breakpoint ever failed to park the read it would pass
without exercising the bug, as with the existing break/resume tests.

Signed-off-by: Denis V. Lunev <[email protected]>
Message-ID: <[email protected]>
Signed-off-by: Philippe Mathieu-Daudé <[email protected]>
(cherry picked from commit cb7bc10385)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-08 13:01:49 +03:00
Denis V. Lunev 79bdb9078e hw/ide/ahci: cancel in-flight buffered reads on command engine restart
ATAPI CD reads are issued through ide_buffered_readv()
(cd_read_sector() and ide_atapi_cmd_read_dma_cb() in hw/ide/atapi.c).
The PIO path discards the returned aiocb; the DMA path stores it in
s->bus->dma->aiocb.

A guest can stop and restart a port's command engine
(PxCMD.ST 1 -> 0 -> 1) while such a read is still in flight. Stopping
the engine unmaps the command list (ahci_unmap_clb_address()) and
restarting it re-maps the list and clears AHCIDevice.cur_cmd to NULL,
but nothing tears down the outstanding read. This path does not run
ide_reset(), so the drive's transfer state is preserved and the read
still completes. Its callbacks then dereference the stale or NULL
cur_cmd in the AHCI transfer helpers:

  PIO: cd_read_sector_cb() -> ide_atapi_cmd_reply_end() ->
       ide_transfer_start_norecurse() -> ahci_pio_transfer()

  DMA: ide_atapi_cmd_read_dma_cb() -> ahci_dma_rw_buf() ->
       ahci_populate_sglist()

Both crash with a NULL cur_cmd; the PIO variant has been seen in the
field.

Cancel the outstanding I/O when the command list is unmapped, reusing
ide_cancel_dma_sync() as the ATAPI DEVICE RESET command does. It runs
the completion callback with -ECANCELED (which tears down
s->bus->dma->aiocb for the DMA case) and orphans the buffered request,
so the eventual asynchronous completion is a no-op. Merely setting the
orphaned flag is not enough: it would leave s->bus->dma->aiocb pointing
at a freed aiocb that a later reset would cancel.

Fixes: 1d8c11d631 ("ide: add support for IDEBufferedRequest")
Signed-off-by: Denis V. Lunev <[email protected]>
Message-ID: <[email protected]>
[PMD: Use ide_bus_active_if()]
Signed-off-by: Philippe Mathieu-Daudé <[email protected]>
(cherry picked from commit d9f78431d8)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-08 13:01:49 +03:00
Junjie Cao af3338cb60 hw/display/ati: guard against zero bpp in ati_host_data_flush
ati_bpp_from_datatype() returns 0 for unrecognized dp_datatype nibble
values (0, 1, or >= 7). ati_host_data_flush() only guards against the
bpp == 24 case but not bpp == 0, leading to:

  1. Division by zero at "pix_count /= ctx.bpp" (SIGFPE) when
     src_datatype is SRC_COLOR.
  2. g_assert_not_reached() in stn_he_p() when bypp (= bpp/8 = 0)
     hits the default case of the size switch.

Both are guest-triggerable via MMIO writes to the dp_datatype register
while a HOST_DATA blit is active.

Add an explicit bpp == 0 check with LOG_GUEST_ERROR before proceeding
with the blit, consistent with the existing check in ati_2d_do_blt().

Cc: [email protected]
Reported-by: Feifan Qian <[email protected]>
Signed-off-by: Junjie Cao <[email protected]>
Reviewed-by: Chad Jablonski <[email protected]>
Message-ID: <[email protected]>
Signed-off-by: Philippe Mathieu-Daudé <[email protected]>
(cherry picked from commit 90f8e5c307)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-08 13:01:49 +03:00
Junjie Cao 8387fa0979 hw/display/ati: reset host_data.next in write handler after flush
ati_host_data_flush() resets host_data.next only on its success path.
When it returns early (unsupported bpp, direction, src_source, or
src_datatype), next remains stale at >= 4. The next HOST_DATA write
then stores a guest-controlled dword at acc[4+], overflowing the
4-element accumulator array.

Fix this by resetting next unconditionally in the write handler after
calling ati_host_data_flush() or ati_host_data_finish(), and removing
the reset from inside ati_host_data_flush(). This ensures the write
handler owns the full lifecycle of the accumulator index regardless of
flush success or failure.

Cc: [email protected]
Reported-by: Feifan Qian <[email protected]>
Resolves: https://lore.kernel.org/qemu-devel/Czyl6yVfL6sHl_o1kRk8N_LpwXMMRVhO9vgz1qCVJFagn9D4nHSKuiux39iOLty0Q3acxQq_FeovPhTQvSKus2htwjI9lTajLZmqovr0Wxs=@proton.me/
Signed-off-by: Junjie Cao <[email protected]>
Reviewed-by: Chad Jablonski <[email protected]>
Message-ID: <[email protected]>
Signed-off-by: Philippe Mathieu-Daudé <[email protected]>
(cherry picked from commit 3565faa0ac)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-08 13:01:49 +03:00
Torin Carey abb4251926 hw/misc/edu: restrict dma access to dma buffer
The EDU device doesn't enforce any bound checks on the addresses provided,
allowing users of the device to perform arbitrary reads and writes to QEMU's
address space.

Signed-off-by: Torin Carey <[email protected]>
Cc: [email protected]
Fixes: 7b608e5d6c ("hw: misc: edu: use qemu_log_mask instead of hw_error")
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3852
Reviewed-by: Peter Maydell <[email protected]>
Message-ID: <[email protected]>
Signed-off-by: Philippe Mathieu-Daudé <[email protected]>
(cherry picked from commit 42f599172a)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-08 13:01:49 +03:00
Miao Wang 1a02d1d0c8 target/loongarch: Enable TARGET_PAGE_BITS_VARY for loongarch64 user-only
Hard coding PAGE_SIZE to 4K will prevent user-only emulation from
working on hosts with 16K page size.

Fixes: 1d832c19db ("target/loongarch: Support 4K page size")
Fixes: qemu-project/qemu#3651

Signed-off-by: Miao Wang <[email protected]>
Reviewed-by: Song Gao <[email protected]>
Message-ID: <[email protected]>
Signed-off-by: Song Gao <[email protected]>
(cherry picked from commit e819c126a8)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-08 13:01:49 +03:00
Eric Farman d34e721577 s390x/css: limit number of CHPIDs in description
virtio-ccw uses a single virtual CHPID for all devices and
device-types, but vfio-ccw (passthrough) shares real CHPID
information with the guest. A sufficiently large passthrough
configuration would exceed the defined response payload.

Fix this by limiting the number of CHPID descriptions that
are returned based on the given response format.

Cc: [email protected]
Reviewed-by: Christian Borntraeger <[email protected]>
Reviewed-by: Matthew Rosato <[email protected]>
Signed-off-by: Eric Farman <[email protected]>
Signed-off-by: Christian Borntraeger <[email protected]>
Message-ID: <[email protected]>
Signed-off-by: Cornelia Huck <[email protected]>
(cherry picked from commit 22f2da06a8)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-08 13:01:49 +03:00
Matthew Rosato 1e397bc2e6 s390x/ioinst: Require strict length and format for SEI CHSC handler
Ensure SEI commands that are received are of the appropriate length and
format before handling.

Cc: [email protected]
Fixes: 8cba80c3a0 ("s390: Add PCI bus support")
Reviewed-by: Christian Borntraeger <[email protected]>
Reviewed-by: Farhan Ali <[email protected]>
Reviewed-by: Eric Farman <[email protected]>
Signed-off-by: Matthew Rosato <[email protected]>
Signed-off-by: Christian Borntraeger <[email protected]>
Message-ID: <[email protected]>
Signed-off-by: Cornelia Huck <[email protected]>
(cherry picked from commit 386268daea)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-08 13:01:49 +03:00
Matthew Rosato fe98d317b1 s390x/pci: Shrink RPCIT ranges to registered window
Today, if a RPCIT instruction is presented from the guest whose range
exceeds the previously-registered IOAT, QEMU will process the range
so long as 1) the specified range at least partially overlaps with
what was previously registered and 2) the guest has valid IOAT entries
in its table.  If the entries are not present (invalid), then the
RPCIT will unnecessarily spend time reporting the invalid
region/segment entries.

Optimize this path by exiting immediately if the requested range falls
completely outside of the previously-registered range or if the
requested range ends before it starts (which would only occur if the
guest-specified address + length would overflow a u64).  Otherwise,
clamp the request to only the portion of the range that overlaps with
what was previously registered, effectively ignoring the portion
outside of the registered range.

Cc: [email protected]
Fixes: 5d1abf2344 ("s390x/pci: enforce zPCI state checking")
Reviewed-by: Christian Borntraeger <[email protected]>
Reviewed-by: Farhan Ali <[email protected]>
Signed-off-by: Matthew Rosato <[email protected]>
Signed-off-by: Christian Borntraeger <[email protected]>
Message-ID: <[email protected]>
Signed-off-by: Cornelia Huck <[email protected]>
(cherry picked from commit b8c8ec1d75)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-08 13:01:49 +03:00
Matthew Rosato f4d46fb090 s390x/pci: Tighten region detection for BAR read/write
For PCISTG/PCISTB/PCILG instruction emulation, ensure that the offset
and length provided by the guest does not overflow, and only return
a memory region when the specified offset+length combination matches
an existing subregion or the parent region.

Cc: [email protected]
Fixes: 4f6482bfe3 ("s390x/pci: search for subregion inside the BARs")
Signed-off-by: Matthew Rosato <[email protected]>
Reviewed-by: Christian Borntraeger <[email protected]>
Reviewed-by: Farhan Ali <[email protected]>
Signed-off-by: Christian Borntraeger <[email protected]>
Message-ID: <[email protected]>
Signed-off-by: Cornelia Huck <[email protected]>
(cherry picked from commit 2d709a70c7)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-08 13:01:49 +03:00
Christian Borntraeger cfde0a53f2 s390x/sclp: reject invalid write event data headers
If a guest submits an sccb with a tiny header length but a large number
of event mask entries, the write_event_mask handler will
1. return the wrong RC (ok instead of error)
2. write to memory after the allocated sccb in qemu host memory.

Add the necessary checks.

Cc: [email protected]
Reviewed-by: Hendrik Brueckner <[email protected]>
Reviewed-by: Matthew Rosato <[email protected]>
Reviewed-by: Eric Farman <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Signed-off-by: Christian Borntraeger <[email protected]>
Message-ID: <[email protected]>
Signed-off-by: Cornelia Huck <[email protected]>
(cherry picked from commit d88cd8f557)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-08 13:01:49 +03:00
Keith Busch 514eee6c4c hw/nvme: ensure sgl forward progress
A degenerate host can create segment loops of zero-byte data descriptors
that the controller never breaks out of. While the spec allows zero
length segments, it provides no guidance on handling loops. It
makes no sense for a host to submit such a descriptor anyway since it
can and trivially should point to the next transfer segment, so don't
even try to work with such behavior. Just reject the command,
terminating the loop.

Cc: [email protected]
Reported-by: Feifan Qian <[email protected]>
Reported-by: boy juju <[email protected]>
Signed-off-by: Keith Busch <[email protected]>
Reviewed-by: Klaus Jensen <[email protected]>
Signed-off-by: Klaus Jensen <[email protected]>
(cherry picked from commit 034baf047f)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-07 22:42:20 +03:00
Jesper Wendel Devantier 0add8af2f0 hw/nvme: fix FDP set FDP events
Addresses an issue reported whereby user-provided event type values
could trigger two issues:

 1. if provided event_type == 0xff -> out-of-bounds access

 2. if provided event_type > 7 -> generate a value too large for the
    u8 event mask.

This patch fixes (1) by correctly adjusting the length of the look-up
array to be 256 values.
This patch fixes (2) by:
  a. changing the event_type mask to 64bit, matching
     NvmeRuHandle.event_filter
  b. Matching the behavior of Get Feature - FDP Events by skipping
     event type values which we do not support.
     5.2.26.1.21 of the 2.3 Base specification does not explicitly
     tell us to reject unsupported event type values.
  c. Documenting in the event type lookup table, that supporting
     event types greater than 63 requires refactoring the masking
     code.

Cc: [email protected]
Reported-by: jaeyeong <[email protected]>
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3631
Signed-off-by: Jesper Wendel Devantier <[email protected]>
Reviewed-by: Klaus Jensen <[email protected]>
Signed-off-by: Klaus Jensen <[email protected]>
(cherry picked from commit ec917cd499)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-07 22:42:20 +03:00
Alex Bennée b3676f7246 hw/arm: use cortex-a9 mpcore base for CBAR on npcm7xx machines
CBAR is an IMPDEF register and according to the A9 TRM [1]:

  In Cortex-A9 MPCore implementations, the base address is reset to
  PERIPHBASE[31:13] so that software can determine the location of the
  private memory region [2].

If it doesn't we will confuse the Linux kernel as it probes the system
SCU registers [3] and erroneously assumes the system is a buggy Aegis SOC
and nerf the emission of SEV instructions, deadlocking any WFE's in
the kernel (or QEMU smpboot code).

[1] https://developer.arm.com/documentation/ddi0388/i/system-control/register-descriptions/configuration-base-address-register
[2] https://developer.arm.com/documentation/ddi0407/g/Introduction/Private-Memory-Region
[3] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/arm/kernel/head.S?h=v7.1#n550

Fixes: 2d8f048c25 ("hw/arm: Add NPCM730 and NPCM750 SoC models")
Cc: [email protected]
Signed-off-by: Alex Bennée <[email protected]>
Reviewed-by: Peter Maydell <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Message-id: [email protected]
Suggested-by: Arnd Bergmann <[email protected]>
Reviewed-by: Peter Maydell <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Signed-off-by: Peter Maydell <[email protected]>
(cherry picked from commit 62b425bec3)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-07 18:29:14 +03:00
Oliver Upton 47db3ee014 target/arm: Only evaluate SCR_EL3.PIEN if ARM_FEATURE_EL3 is present
Running KVM with (as of writing, out-of-tree) support for FEAT_S2PIE
on -cpu max gets stuck in an infinite loop of stage-2 permission faults
due to the PTW incorrectly using an effective value of 0 for S2PIR_EL2.

Similar to how S1PIE is handled, only use the IMPLEMENTATION SPECIFIC
value of 0 for S2PIR_EL2 if EL3 is implemented and PIEN=0.

Cc: [email protected]
Fixes: a811c5dafb ("target/arm: Implement get_S2prot_indirect")
Reviewed-by: Richard Henderson <[email protected]>
Signed-off-by: Oliver Upton <[email protected]>
Message-id: [email protected]
[PMM: removed hardcoded tab]
Signed-off-by: Peter Maydell <[email protected]>
(cherry picked from commit d77a93ca4b)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-07 18:28:22 +03:00
Feifan Qian db11e34db8 hw/net/fsl_etsec: validate FCB offsets in process_tx_fcb()
The TX Frame Control Block (FCB) is prepended to a TX frame when
BD_TX_TOEUN is set. It contains two guest-controlled u8 offset
fields that process_tx_fcb() uses to locate L3/L4 headers within
the frame buffer:

  l3_header_offset = FCB byte 3 (0..255)
  l4_header_offset = FCB byte 2 (0..255)

These offsets are applied without any bounds check. When the
UDP-no-CTU branch is taken, the function writes zero to
l4_header[6] and l4_header[7]. With both offsets set to 0xFF the
write target is:

  tx_buffer + 8 + 255 + 255 + 6/7 = tx_buffer + 525

A malicious guest can therefore corrupt up to 509 bytes of heap
memory beyond a minimally-sized (16 B) TX frame.

Fix: reject the frame and log a guest error when the minimum
required buffer length

  8 (FCB) + l3_header_offset + l4_header_offset + 8

exceeds tx_buffer_len. Move the l3_header and l4_header pointer
declarations past the new guard so that out-of-bounds pointers
are never materialised.

Cc: [email protected]
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3517
Signed-off-by: Feifan Qian <[email protected]>
Reviewed-by: Peter Maydell <[email protected]>
Signed-off-by: Peter Maydell <[email protected]>
(cherry picked from commit bc22c7e418)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-07 18:27:37 +03:00
Junjie Cao 0d228637f8 virtio-net: validate RSS indirections_len in post_load
virtio_net_handle_rss() enforces that indirections_len is a non-zero
power of two no larger than VIRTIO_NET_RSS_MAX_TABLE_LEN, but
virtio_net_rss_post_load() applies none of these checks to values
restored from the migration stream.

A corrupted save file or crafted migration stream can set
indirections_len to 0.  Even if it also clears redirect,
virtio_load() calls set_features_nocheck() after the device vmstate
(including the RSS subsection and its post_load) has already been
loaded, re-deriving redirect from the negotiated guest features.
When VIRTIO_NET_F_RSS was negotiated, redirect is set back to true
regardless of the migration stream value.  The receive path then
computes

    hash & (indirections_len - 1)   /* wraps to 0xFFFFFFFF via int promotion */

and uses the result to index into indirections_table, which was not
allocated by the VMState loader when the element count is zero (see
vmstate_handle_alloc()), resulting in a NULL pointer dereference that
crashes QEMU:

  #0  virtio_net_process_rss    ../hw/net/virtio-net.c:1901
  #1  virtio_net_receive_rcu    ../hw/net/virtio-net.c:1921
  #2  virtio_net_do_receive     ../hw/net/virtio-net.c:2061
  #3  nc_sendv_compat           ../net/net.c:823
  #4  qemu_deliver_packet_iov   ../net/net.c:870

The RSS subsection is only loaded when rss_data.enabled is true (via
virtio_net_rss_needed()), and the command path always produces
indirections_len in {1, 2, 4, …, 128}, so an unconditional check
cannot reject a legitimate migration stream.

Factor the validation into virtio_net_rss_indirections_len_valid()
and call it from both virtio_net_handle_rss() and
virtio_net_rss_post_load().

Fixes: e41b711485 ("virtio-net: add migration support for RSS and hash report")
Cc: [email protected]
Signed-off-by: Junjie Cao <[email protected]>
Reviewed-by: Michael S. Tsirkin <[email protected]>
Signed-off-by: Michael S. Tsirkin <[email protected]>
Message-ID: <[email protected]>
(cherry picked from commit 32a90850e1)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-07 11:03:21 +03:00
Laurent Vivier 7fd7448e68 hw/char/virtio-serial-bus: fix guest-triggerable OOM in control_out()
A malicious guest can craft virtqueue descriptors with arbitrary lengths.
control_out() calls iov_size() on the guest-supplied scatter-gather list
and passes the result directly to g_malloc(), allowing a guest to force
QEMU to attempt multi-gigabyte allocations and crash the host process.

Fix this by copying at most sizeof(struct virtio_console_control) into a
stack-local variable instead of allocating a buffer sized by the guest.
handle_control_message() only accesses the fixed-size id, event, and
value fields, so no data beyond the struct was ever needed.

Cc: [email protected]
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3585
Signed-off-by: Laurent Vivier <[email protected]>
Reviewed-by: Michael S. Tsirkin <[email protected]>
Signed-off-by: Michael S. Tsirkin <[email protected]>
Message-ID: <[email protected]>
(cherry picked from commit 36b37f8494)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-07 11:01:33 +03:00
Daniel Henrique Barboza 1bfd63d6d0 hw/riscv/riscv-iommu.c: always fault with SADE=0 and A=0
riscv-iommu spec: "If SADE is 1, the IOMMU updates A and D bits in
first-stage PTEs atomically. If SADE is 0, the IOMMU causes a
page-fault corresponding to the original access type if the
A bit is 0 or if the memory access is a store and the D bit is 0.".

Note that SADE=0 and A=0 will always cause a fault regardless of the
original access type.  Right now we're faulting in this case just for
reads.

Fixes: 0c54acb824 ("hw/riscv: add RISC-V IOMMU base emulation")
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3551
Signed-off-by: Daniel Henrique Barboza <[email protected]>
Acked-by: Alistair Francis <[email protected]>
Reviewed-by: Nutty Liu <[email protected]>
Message-ID: <[email protected]>
Signed-off-by: Alistair Francis <[email protected]>
(cherry picked from commit 64ce9ac187)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-03 22:12:54 +03:00
SeungJu Cheon 7209324e5e target/riscv: Apply UXL WARL handling to vsstatus
write_mstatus() already handles the reserved UXL value by writing a
legal value instead.

Apply the same handling when writing vsstatus so that reserved UXL
values follow the same WARL behavior.

Factor the common logic into a local helper riscv_write_uxl() and use
it for both mstatus and vsstatus.

Suggested-by: Daniel Henrique Barboza <[email protected]>
Fixes: f310df58bd ("target/riscv: Enable uxl field write")
Signed-off-by: SeungJu Cheon <[email protected]>
Reviewed-by: Daniel Henrique Barboza <[email protected]>
Message-ID: <[email protected]>
Signed-off-by: Alistair Francis <[email protected]>
(cherry picked from commit dcd0285177)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-03 22:11:26 +03:00
ZhengXiang Qin 1f4f980e53 target/riscv: avoid abort when reading vtype before env->xl is set
TCG plugins may read registers from the vcpu_init_cb() callback.  For
vtype, this reaches read_vtype() before env->xl has been initialized.

In that case read_vtype() currently hits g_assert_not_reached() because
env->xl is zero.  Fall back to the CPU's maximum XLEN only for this
early-init case.

Fixes: 638181a180 ("core/cpu-common: initialise plugin state before thread creation")
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3545
Signed-off-by: ZhengXiang Qin <[email protected]>
Reviewed-by: Daniel Henrique Barboza <[email protected]>
Message-ID: <[email protected]>
Signed-off-by: Alistair Francis <[email protected]>
(cherry picked from commit 46d96da130)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-03 22:10:04 +03:00
Qingwei Hu 27f40e77e7 hw/riscv/virt-acpi-build: Fix RINTC PLIC context ID for KVM
Each RISC-V MADT RINTC entry contains an External Interrupt Controller
ID field. On the virt machine without AIA, this field identifies the
S-mode PLIC context associated with the hart.

TCG virt has both M-mode and S-mode PLIC contexts, so the S-mode context
ID is odd and 2 * local_cpu_id + 1 is correct. KVM virt exposes only
S-mode PLIC contexts, and those contexts are numbered contiguously from
0. Reporting the TCG context ID for KVM makes the guest enable a
different PLIC context from the one used by QEMU.

With ACPI enabled, this can leave PCI INTx interrupts pending in QEMU
while the guest-programmed PLIC context remains disabled. A virtio-blk
root disk can then stall during boot because its first interrupt is never
delivered.

Use local_cpu_id for KVM and keep the existing odd S-mode context ID for
TCG.

Fixes: d641da6ed4 ("hw/riscv/virt-acpi-build.c: Add PLIC in MADT")
Signed-off-by: Qingwei Hu <[email protected]>
Reviewed-by: Nutty Liu <[email protected]>
Reviewed-by: Sunil V L <[email protected]>
Message-ID: <[email protected]>
Signed-off-by: Alistair Francis <[email protected]>
(cherry picked from commit fdfcd98f66)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-03 22:09:40 +03:00
Inochi Amaoto f08d947863 target/riscv: Check PMP before updating PTE
According to the RISC-V spec, the PTE update is a supervisor write
operations, and it should also follow the CPU PMP configuration like
the PTE read.

Cc: [email protected]
Signed-off-by: Inochi Amaoto <[email protected]>
Reviewed-by: Alistair Francis <[email protected]>
Message-ID: <[email protected]>
Signed-off-by: Alistair Francis <[email protected]>
(cherry picked from commit fa2cf74883)
Signed-off-by: Michael Tokarev <[email protected]>
2026-07-02 13:56:35 +03:00
Christian Schoenebeck 1c1c043fba hw/9pfs/local: harden local_fid_fd() on FID types
local_fid_fd() returns fs->fd for any FID type that is not P9_FID_DIR.

Since P9_FID_XATTR and P9_FID_NONE share union V9fsFidOpenState, calling
local_fid_fd() on these types misinterprets xattr state as a file
descriptor, potentially leading to undefined behaviour or information
disclosure.

Even though we are catching these FID type mismatches on protocol level
in 9p.c already, previous patches proofed this to be error prone.

So let's add another safety layer in local_fid_fd() that would return -1
if the FID type would not possess a valid file descriptor, to prevent
wrong file descriptors from reaching fs backend calls.

Link: https://lore.kernel.org/qemu-devel/531f6b81bc1bf1a48c3d4afaa60a65db10511041.1781621428.git.qemu_oss@crudebyte.com
Signed-off-by: Christian Schoenebeck <[email protected]>
(cherry picked from commit 75893c058b)
Signed-off-by: Michael Tokarev <[email protected]>
2026-06-30 09:37:33 +03:00
Christian Schoenebeck 65132787e6 hw/9pfs: fix invalid union access by v9fs_co_fstat()
The individual FID types (P9_FID_NONE, P9_FID_FILE, P9_FID_DIR, P9_FID_XATTR)
share union V9fsFidOpenState with FID-type specific fields. Accessing any of
the union fields must comply with the FID-type to avoid undefined behaviour
or information disclosure.

Fix this in v9fs_lock() and v9fs_getlock() by checking if FID has a valid
file descriptor before calling v9fs_co_fstat().

Fixes: 10b468bdc5 ("virtio-9p: Implement TXATTRCREATE")
Link: https://lore.kernel.org/qemu-devel/4b33cd1aaa2551efda220a6f651e3660d27f4746.1781621428.git.qemu_oss@crudebyte.com
Signed-off-by: Christian Schoenebeck <[email protected]>
(cherry picked from commit c3aa2491cd)
Signed-off-by: Michael Tokarev <[email protected]>
2026-06-30 09:37:33 +03:00
Christian Schoenebeck 11088e1fd0 hw/9pfs: fix invalid union access by v9fs_co_fsync()
The individual FID types (P9_FID_NONE, P9_FID_FILE, P9_FID_DIR, P9_FID_XATTR)
share union V9fsFidOpenState with FID-type specific fields. Accessing any of
the union fields must comply with the FID-type to avoid undefined behaviour
or information disclosure.

Fix this in v9fs_fsync() and v9fs_wstat() by checking if FID has a valid file
descriptor before calling v9fs_co_fsync().

Fixes: 10b468bdc5 ("virtio-9p: Implement TXATTRCREATE")
Reported-by: Feifan Qian <[email protected]>
Link: https://lore.kernel.org/qemu-devel/b583e29d5a0776e41263732c93ac9f0da0a6016d.1781621428.git.qemu_oss@crudebyte.com
Signed-off-by: Christian Schoenebeck <[email protected]>
(cherry picked from commit 32cae47c33)
Signed-off-by: Michael Tokarev <[email protected]>
2026-06-30 09:37:33 +03:00
Christian Schoenebeck 64579c0535 tests/9p: add 3 xattr FID limit test cases (local fs driver)
Analogue to the previously added 3 synth tests, add (similar) 3 test
cases using the "local" fs driver to verify correct xattr FID limit
enforcement of 9pfs server with a real filesystem.

These 3 new local tests use the shared test code of the previously
added 3 synth tests. The only difference is that the local fs driver
does not expose the current internal xattr FID counter, so we can't
verify this with the local tests.

This is a slow test (may take several seconds) and therefore
registered as "slow" test and not running by default.

Use -m slow to run this test.

Link: https://lore.kernel.org/qemu-devel/d23fa874df4f474ee7cbe738a35c1483426057f0.1781361555.git.qemu_oss@crudebyte.com
Signed-off-by: Christian Schoenebeck <[email protected]>
(cherry picked from commit 04a62cdfe8)
Signed-off-by: Michael Tokarev <[email protected]>
2026-06-30 09:37:33 +03:00
Christian Schoenebeck 7f949e8d9b tests/9p: add 3 xattr FID limit test cases (synth fs driver)
Add 3 test cases to verify correct xattr FID limit enforcement of
9pfs server.

 - 1. test with default max_xattr=1024
 - 2. test with custom max_xattr=100
 - 3. test with unlimited max_xattr=0

These are tests using the synth driver. Advantage: by using the
synth driver the tests cannot only check when the xattr FID limit
kicks in (server would return an Rlerror response with ENOSPC),
but can also validate the current 9p server internal xattr FID
counter at any moment.

This is a slow test (may take several seconds) and therefore
registered as "slow" test and not running by default.

Use -m slow to run this test.

Link: https://lore.kernel.org/qemu-devel/540c51faa074d9dd736bbf2170084a12288e23ef.1781361555.git.qemu_oss@crudebyte.com
Signed-off-by: Christian Schoenebeck <[email protected]>
(cherry picked from commit 0e1085819e)
Signed-off-by: Michael Tokarev <[email protected]>
2026-06-30 09:37:33 +03:00
Christian Schoenebeck d1225452cf tests/9p: add virtio_9p_add_synth_driver_args() test client function
Add virtio_9p_add_synth_driver_args() to allow appending custom
QEMU options for individual 9p synth tests.

Link: https://lore.kernel.org/qemu-devel/7fe3eca5d17292464676b68d0513052564cd432a.1781361555.git.qemu_oss@crudebyte.com
Signed-off-by: Christian Schoenebeck <[email protected]>
(cherry picked from commit 84525ece68)
Signed-off-by: Michael Tokarev <[email protected]>
2026-06-30 09:37:33 +03:00
Christian Schoenebeck d3b894fd0a tests/9p: increase P9_MAX_SIZE for test client
Increase the maximum 9P message size ('msize') of 9p test client from
4k to 32k to support larger messages.

This is needed for the xattr tests being added with the subsequent
patches which are going to transmit xattrs of size 8k. It would have
also been possible to send them in multiple chunks, however let's not
overcomplicate things.

This new msize is still reasonable small compared to common msize
values on production systems.

Link: https://lore.kernel.org/qemu-devel/2dcb1243c80ea97d085af5171785850cf012be36.1781361555.git.qemu_oss@crudebyte.com
Signed-off-by: Christian Schoenebeck <[email protected]>
(cherry picked from commit df88255543)
Signed-off-by: Michael Tokarev <[email protected]>
2026-06-30 09:37:33 +03:00
Christian Schoenebeck 0067f9b26a hw/9pfs: add xattr count query interface to fs synth driver
Add a synthetic "/stat/xattr_count" file path that, if being read
by 9p client, returns the 9p server internal xattr FID counter to
client.

This allows to test and verify that the xattr FID limit is being
enforced correctly.

Link: https://lore.kernel.org/qemu-devel/357c20fc244c04dcbd36b13aa20a5c9b2034e9f0.1781361555.git.qemu_oss@crudebyte.com
Signed-off-by: Christian Schoenebeck <[email protected]>
(cherry picked from commit 7e42d569a6)
Signed-off-by: Michael Tokarev <[email protected]>
2026-06-30 09:37:33 +03:00
Christian Schoenebeck c25007f4aa hw/9pfs: enable xattr (mockup) support for synth fs driver
The synth backend is used for testing only. Enable xattr operations
by making lsetxattr and lremovexattr callbacks to return success
result.

They are still actually not doing anything, they just pretend to be
working to prevent 9pfs server from erroring out on xattr requests.

This allows the subsequent test case patches to verify xattr FID
limit enforcement.

Link: https://lore.kernel.org/qemu-devel/9c1c7128135f3bd9c2f62a3f64bb730b6a94ec7a.1781361555.git.qemu_oss@crudebyte.com
Signed-off-by: Christian Schoenebeck <[email protected]>
(cherry picked from commit 0e3085ddc7)
Signed-off-by: Michael Tokarev <[email protected]>
2026-06-30 09:37:33 +03:00
Christian Schoenebeck 643292380c tests/9p: add Txattrcreate / Rxattrcreate test client functions
Add v9fs_txattrcreate() and v9fs_rxattrcreate() functions to the
9P test client for testing creation of xattrs with 9pfs server.

Link: https://lore.kernel.org/qemu-devel/5dbc5061dab1f7829fffc40bf89d7ff443e4bcab.1781361555.git.qemu_oss@crudebyte.com
Signed-off-by: Christian Schoenebeck <[email protected]>
(cherry picked from commit 7664feb26f)
Signed-off-by: Michael Tokarev <[email protected]>
2026-06-30 09:37:33 +03:00
Christian Schoenebeck bcdfdefbef tests/9p: add Tclunk / Rclunk test client functions
Add v9fs_tclunk() and v9fs_rclunk() functions to the 9P test client
for closing file handles (or "FIDs") in test cases.

Link: https://lore.kernel.org/qemu-devel/d53f0337eb7f8525a14e394599d809ecf6805e5e.1781361555.git.qemu_oss@crudebyte.com
Signed-off-by: Christian Schoenebeck <[email protected]>
(cherry picked from commit c46150530b)
Signed-off-by: Michael Tokarev <[email protected]>
2026-06-30 09:37:33 +03:00
Christian Schoenebeck e0723f32e5 tests/9p: add Tread / Rread test client functions
Add v9fs_tread() and v9fs_rread() functions to the 9P test client
for reading files from 9pfs server in test cases.

Link: https://lore.kernel.org/qemu-devel/049bdd1e66416f5200fb3d59d2da5e8ec149926d.1781361555.git.qemu_oss@crudebyte.com
Signed-off-by: Christian Schoenebeck <[email protected]>
(cherry picked from commit 54b8f64c42)
Signed-off-by: Michael Tokarev <[email protected]>
2026-06-30 09:37:33 +03:00
Christian Schoenebeck 8fd934f911 qemu-options: document 9pfs max_xattr option
Add documentation for the new "max_xattr" command line option
of 9pfs server, introduced by the previous commit.

Link: https://lore.kernel.org/qemu-devel/b5a1a6ba299a49183d0032d9e4cd5e009d4aae47.1781361555.git.qemu_oss@crudebyte.com
Signed-off-by: Christian Schoenebeck <[email protected]>
(cherry picked from commit 44cb540d2d)
Signed-off-by: Michael Tokarev <[email protected]>
2026-06-30 09:37:33 +03:00
Christian Schoenebeck 5ab98d34b0 hw/9pfs: add max_xattr option
Previous patch introduced a limit of max. 1024 simultaneous xattr FIDs.

This patch introduces an option "max_attr" that allows to override this
limit, just for the case that some user might run into this limit for
some reason, even if unlikely; or for reducing the limit further down
(e.g. that default limit of 1024 would cap at max. 64 MiB host memory,
at least on Linux hosts where the limit per xattr is 64k).

This new "max_xattr" option can be specified with both -fsdev and
-virtfs command line options, with the "local" and the "synth" fs
drivers.

The previous limit of 1024 is preserved as the default value.

Link: https://lore.kernel.org/qemu-devel/b7631ac0d8dde0629bc7c4f2c4185d9f57b962b4.1781361555.git.qemu_oss@crudebyte.com
Signed-off-by: Christian Schoenebeck <[email protected]>
(cherry picked from commit e6116a81f0)
Signed-off-by: Michael Tokarev <[email protected]>
2026-06-30 09:37:33 +03:00
Christian Schoenebeck c57644a542 hw/9pfs: add xattr FID limit to prevent memory exhaustion
Add a limit on the number of simultaneously open xattr FIDs to prevent
host memory exhaustion attacks. Each xattr FID contains a buffer for the
xattr value, and without a limit, a malicious priviliged guest with
direct communication access to 9p server could create a huge number of
xattr FIDs until host memory is eventually exhausted.

Fix this by:

 - add xattr_fid_limit to struct FsContext for the max. amount
 - add xattr_fid_count to struct FsContext for the current amount
 - init xattr_fid_limit with 1024
 - init xattr_fid_count with 0
 - add function xattr_fid_count_inc() to increment the count
 - add function xattr_fid_count_decr() to decrement the count
 - call xattr_fid_count_inc() in Txattrcreate handler
 - call xattr_fid_count_inc() in Txattrwalk handler
 - call xattr_fid_count_decr() when a xattr FID is freed

Additionally:

 - reset the xattr FID counter in virtfs_reset()

When the limit is reached then xattr_fid_count_inc() returns -ENOSPC and
the request handler is aborted on its error path without turning the
FID into an xattr type and without allocating memory for the xattr.

The default value of 1024 was chosen, as (sane usage of) xattr requests
in the 9p protocol are usually very short-lived, and even machines with
128 cores with very high xattr activity should have plenty of head room
without ever hitting this limit.

Fixes: 10b468bdc5 ("virtio-9p: Implement TXATTRCREATE")
Fixes: CVE-2026-8348
Reported-by: Feifan Qian <[email protected]>
Link: https://lore.kernel.org/qemu-devel/eb3787869745d47234fb662600187bf773e1ef8a.1781361555.git.qemu_oss@crudebyte.com
Signed-off-by: Christian Schoenebeck <[email protected]>
(cherry picked from commit 693b296b17)
Signed-off-by: Michael Tokarev <[email protected]>
2026-06-30 09:37:33 +03:00
Christian Schoenebeck d2a298f359 hw/9pfs: cap Treaddir allocation (CVE-2026-9238)
Constrain max_count in v9fs_readdir() to transport's current, real
response buffer size before calling v9fs_do_readdir() to prevent
excessive host memory allocation for specific, crafted, huge
directories (large amount of entries) by bad clients.

Client may send a Treaddir request with a large 'count' parameter, and
while the negotiated 'msize' provides some limit, it accounts for guest
being somewhat faithful on the negotiated 'msize' value throughout the
session.

A bad guest client could have negotiated a large 'msize' but provide a
small reply buffer for Treaddir request, causing QEMU to allocate host
memory proportional to 'msize' before discovering the reply cannot fit.

Possible consequence was a potential DoS by a priviliged guest, causing
a disconnection of guest communication due to transport device being
marked as "broken", however QEMU process would have continued to run with
potentially giant host memory allocation, which might have negative
impact on other services running on host.

Fixes: CVE-2026-9238
Fixes: 2149675b19 ("9pfs: add new function v9fs_co_readdir_many()")
Reported-by: Feifan Qian <[email protected]>
Reviewed-by: Stefano Stabellini <[email protected]>
Link: https://lore.kernel.org/qemu-devel/f81a387a2de4f2172fd5830c5654f49d78102254.1781287774.git.qemu_oss@crudebyte.com
Signed-off-by: Christian Schoenebeck <[email protected]>
(cherry picked from commit 64c6c7e0df)
Signed-off-by: Michael Tokarev <[email protected]>
2026-06-30 09:37:33 +03:00
Christian Schoenebeck 7a65657829 9pfs/xen: implement response_buffer_size callback
Add and implement the response_buffer_size callback for the Xen
transport.

Returns the size of the response buffer from the rings in_sg, as limit
for 9p server while generating a response for supplied PDU.

We use a local iovec array variable in_sg[2] instead of ring->sg, as
ring->sg is only allocated by init_in_iov_from_pdu() and
init_out_iov_from_pdu() during request / response processing.
response_buffer_size() however may be called before those allocators,
which would dereference ring->sg as NULL pointer. The local array
avoids this.

Reviewed-by: Stefano Stabellini <[email protected]>
Link: https://lore.kernel.org/qemu-devel/3b139769eb1d3f9d91ee5281228e6467f9a08b99.1781287774.git.qemu_oss@crudebyte.com
Signed-off-by: Christian Schoenebeck <[email protected]>
(cherry picked from commit 69c8f5e694)
Signed-off-by: Michael Tokarev <[email protected]>
2026-06-30 09:37:33 +03:00
Christian Schoenebeck f72b438cfb 9pfs/virtio: implement response_buffer_size callback
Add and implement the response_buffer_size callback for the virtio
transport.

Returns the actual current virtio response buffer size for the supplied
PDU, which will be used as safety guard for limiting the response size
when generating a 9p response.

Link: https://lore.kernel.org/qemu-devel/5bbed2768f7a0da8fa2be183e75928c5d1ef691d.1781287774.git.qemu_oss@crudebyte.com
Signed-off-by: Christian Schoenebeck <[email protected]>
(cherry picked from commit 12bcbdca8a)
Signed-off-by: Michael Tokarev <[email protected]>
2026-06-30 09:37:33 +03:00
Christian Schoenebeck c73afc39d6 hw/9pfs: add response_buffer_size transport callback
Add a new callback to the V9fsTransport interface that allows each transport
to provide the real size of its current response buffer.

This is needed for subsequent safety guards that will limit generated
responses appropriately before trying to allocate, generate, and send a
response to guest.

This is especially required for request handlers that need to allocate
dynamic and potentially large host memory for generating a response. These
safety guards are mandatory to counter bad clients that try to trick server
by supplying response buffers being smaller than the previously negotiated
msize value.

Link: https://lore.kernel.org/qemu-devel/703ed8ce4401c4550ef2cd99f30ab808665d6e85.1781287774.git.qemu_oss@crudebyte.com
Signed-off-by: Christian Schoenebeck <[email protected]>
(cherry picked from commit 4b615eaa1b)
Signed-off-by: Michael Tokarev <[email protected]>
2026-06-30 09:37:33 +03:00
Christian Schoenebeck 9c98cdfed9 hw/9pfs: cap negotiated msize to transport limit
The 'msize' parameter negotiated during Tversion handshake can be
arbitrarily large as requested by the guest. So far 9p server accepted
any msize value suggested by guest, i.e. server did not cap it at all,
no matter how large, as in practice the upper limit of msize is a client
capability. But as subsequent's security patch shows, capping msize on
server side makes sense as additional safety-net.

Let's cap msize to transport's theoretical limit for msize, mainly to
prevent a bad client from triggering excessive host memory allocations
throughout the session.

We intentionally don't cap msize to transport's current, real response
buffer size, as the response buffer size may vary between individual
requests.

Link: https://lore.kernel.org/qemu-devel/2105e9a3578c6f751bb64af55c16dd953f393f20.1781287774.git.qemu_oss@crudebyte.com
Signed-off-by: Christian Schoenebeck <[email protected]>
(cherry picked from commit bb5ab96e35)
Signed-off-by: Michael Tokarev <[email protected]>
2026-06-30 09:37:33 +03:00
Christian Schoenebeck 1c0bbd8aa9 9pfs/xen: implement msize_limit callback
Add and implement the msize_limit callback for the Xen transport.

The limit is calculated using XEN_FLEX_RING_SIZE() based on the
negotiated ring_order. For the theoretical maximum ring_order of 9,
this results in a maximum 'msize' of 1048576 bytes (1 MiB).

The minimum limit of all rings is picked, because multiple rings
could theoretically have different ring_orders.

Reviewed-by: Stefano Stabellini <[email protected]>
Link: https://lore.kernel.org/qemu-devel/9471786bc47b93e822f6c6233a83f2b9f61e6c82.1781287774.git.qemu_oss@crudebyte.com
Signed-off-by: Christian Schoenebeck <[email protected]>
(cherry picked from commit 815d1799c3)
Signed-off-by: Michael Tokarev <[email protected]>
2026-06-30 09:37:33 +03:00
Christian Schoenebeck cb02324eff 9pfs/virtio: implement msize_limit callback
Add and implement the msize_limit callback for the virtio transport.

This new callback function provides the theoretical maximum 'msize'
value supported by this virtio transport.

The limit is calculated as (VIRTQUEUE_MAX_SIZE - 2) * 4096 bytes,
where 2 virtio descriptors are lost exactly for:

  - 1 descriptor for the original request (typically being small)

  - 1 descriptor as indirect table pointer (when used), which just
    contains a pointer to the separate sglist containing the
    response's actual payload data

And 4096 bytes are assumed as standard page size used by Linux 9p
client. This results in a maximum 'msize' of 4186112 bytes.

Theoretically Linux client could support a much larger size, e.g. by
using multiple consecutive pages per sg entry / descriptor. However
that's currently not the case and unlikely to change any time soon.
And due to recent security issues, let's handle this limit
conservatively until really necessary to be raised.

Link: https://lore.kernel.org/qemu-devel/4c34426bc906e19423e7e2389c419c2e972d9b9b.1781287774.git.qemu_oss@crudebyte.com
Signed-off-by: Christian Schoenebeck <[email protected]>
(cherry picked from commit 4a1a2fa4d3)
Signed-off-by: Michael Tokarev <[email protected]>
2026-06-30 09:37:33 +03:00
Christian Schoenebeck 63a86a2d8c hw/9pfs: add msize_limit transport callback
Add a new callback 'msize_limit' to the V9fsTransport structure.

This allows each transport implementation to provide its theoretical
maximum 'msize' value, which will be used to cap the negotiated
msize during Tversion handshake.

Link: https://lore.kernel.org/qemu-devel/7c4e53eb73c0580d7a321dbf3823ba5647652298.1781287774.git.qemu_oss@crudebyte.com
Signed-off-by: Christian Schoenebeck <[email protected]>
(cherry picked from commit a1c0e5a737)
Signed-off-by: Michael Tokarev <[email protected]>
2026-06-30 09:37:33 +03:00
Christian Borntraeger 8672445417 s390x/kvm: clamp stsi 3.2.2 size
The stsi 3.2.2 page is being prepared by the kvm module and the size is
clamped by the kernel. As the memory is mapped in the guest, another
guest VCPU could race and overwrite the count and messing up the move
operation. For any out of bound count, fall back to the kernel buffer.

Cc: [email protected]
Signed-off-by: Christian Borntraeger <[email protected]>
Reviewed-by: Eric Farman <[email protected]>
Message-ID: <[email protected]>
Signed-off-by: Cornelia Huck <[email protected]>
(cherry picked from commit a57e4612b6)
Signed-off-by: Michael Tokarev <[email protected]>
2026-06-29 21:37:30 +03:00
Marc-André Lureau ec114fa0d4 ui/gtk: fix bad widget realize on non-GFX VC
The GTK VirtualConsole is a union, it may be .gfx or .vte depending on
the type.

Fixes: 565f85a9c2 ("ui/gtk: force realization of drawing area")
Reviewed-by: Daniel P. Berrangé <[email protected]>
Reviewed-by: Akihiko Odaki <[email protected].i.u-tokyo.ac.jp>
Signed-off-by: Marc-André Lureau <[email protected]>
Message-ID: <[email protected]>
(cherry picked from commit 27f6d5ba9c)
Signed-off-by: Michael Tokarev <[email protected]>
2026-06-26 07:44:29 +03:00
Emmanuel Blot f8b12be74d meson: build macOS signed binary as part of the default target
Signed-off-by: Emmanuel Blot <[email protected]>
Tested-by: Pierrick Bouvier <[email protected]>
Reviewed-by: Pierrick Bouvier <[email protected]>
Message-ID: <[email protected]>
Signed-off-by: Philippe Mathieu-Daudé <[email protected]>
(cherry picked from commit eef29e060d)
Signed-off-by: Michael Tokarev <[email protected]>
2026-06-25 14:51:32 +03:00
117 changed files with 2051 additions and 332 deletions

No files matched your search

+1 -1
View File
@@ -1 +1 @@
11.0.2
11.0.3
+23 -28
View File
@@ -925,6 +925,7 @@ static void do_tb_phys_invalidate(TranslationBlock *tb, bool rm_from_page_list)
uint32_t orig_cflags = tb_cflags(tb);
assert_memory_lock();
qemu_thread_jit_write();
/* make sure no further incoming jumps will be chained to this TB */
qemu_spin_lock(&tb->jmp_lock);
@@ -935,33 +936,27 @@ static void do_tb_phys_invalidate(TranslationBlock *tb, bool rm_from_page_list)
phys_pc = tb_page_addr0(tb);
h = tb_hash_func(phys_pc, (orig_cflags & CF_PCREL ? 0 : tb->pc),
tb->flags, tb->cs_base, orig_cflags);
if (!qht_remove(&tb_ctx.htable, tb, h)) {
return;
if (qht_remove(&tb_ctx.htable, tb, h)) {
/* remove the TB from the page list */
if (rm_from_page_list) {
tb_remove(tb);
}
/* remove the TB from the hash list */
tb_jmp_cache_inval_tb(tb);
/* suppress this TB from the two jump lists */
tb_remove_from_jmp_list(tb, 0);
tb_remove_from_jmp_list(tb, 1);
/* suppress any remaining jumps to this TB */
tb_jmp_unlink(tb);
qatomic_set(&tb_ctx.tb_phys_invalidate_count,
tb_ctx.tb_phys_invalidate_count + 1);
}
/* remove the TB from the page list */
if (rm_from_page_list) {
tb_remove(tb);
}
/* remove the TB from the hash list */
tb_jmp_cache_inval_tb(tb);
/* suppress this TB from the two jump lists */
tb_remove_from_jmp_list(tb, 0);
tb_remove_from_jmp_list(tb, 1);
/* suppress any remaining jumps to this TB */
tb_jmp_unlink(tb);
qatomic_set(&tb_ctx.tb_phys_invalidate_count,
tb_ctx.tb_phys_invalidate_count + 1);
}
static void tb_phys_invalidate__locked(TranslationBlock *tb)
{
qemu_thread_jit_write();
do_tb_phys_invalidate(tb, true);
qemu_thread_jit_execute();
}
@@ -1030,7 +1025,7 @@ void tb_invalidate_phys_range(CPUState *cpu, tb_page_addr_t start,
assert_memory_lock();
PAGE_FOR_EACH_TB(start, last, unused, tb, n) {
tb_phys_invalidate__locked(tb);
do_tb_phys_invalidate(tb, true);
}
}
@@ -1091,7 +1086,7 @@ bool tb_invalidate_phys_page_unwind(CPUState *cpu, tb_page_addr_t addr,
current_tb_modified = true;
cpu_restore_state_from_tb(cpu, current_tb, pc);
}
tb_phys_invalidate__locked(tb);
do_tb_phys_invalidate(tb, true);
}
if (current_tb_modified) {
@@ -1156,7 +1151,7 @@ tb_invalidate_phys_page_range__locked(CPUState *cpu,
current_tb_modified = true;
cpu_restore_state_from_tb(cpu, current_tb, retaddr);
}
tb_phys_invalidate__locked(tb);
do_tb_phys_invalidate(tb, true);
}
}
+23 -18
View File
@@ -238,13 +238,16 @@ void page_dump(FILE *f)
int page_get_flags(vaddr address)
{
PageFlagsNode *p = pageflags_find(address, address);
PageFlagsNode *p;
RCU_READ_LOCK_GUARD();
/*
* See util/interval-tree.c re lockless lookups: no false positives but
* there are false negatives. If we find nothing, retry with the mmap
* lock acquired.
*/
p = pageflags_find(address, address);
if (p) {
return p->flags;
}
@@ -300,15 +303,15 @@ static void pageflags_create_merge(vaddr start, vaddr last, int flags)
if (prev) {
if (next) {
prev->itree.last = next->itree.last;
pageflags_create(prev->itree.start, next->itree.last, flags);
g_free_rcu(next, rcu);
} else {
prev->itree.last = last;
pageflags_create(prev->itree.start, last, flags);
}
interval_tree_insert(&prev->itree, &pageflags_root);
g_free_rcu(prev, rcu);
} else if (next) {
next->itree.start = start;
interval_tree_insert(&next->itree, &pageflags_root);
pageflags_create(start, next->itree.last, flags);
g_free_rcu(next, rcu);
} else {
pageflags_create(start, last, flags);
}
@@ -370,8 +373,8 @@ static bool pageflags_set_clear(vaddr start, vaddr last,
if (set_flags != merge_flags) {
if (p_start < start) {
interval_tree_remove(&p->itree, &pageflags_root);
p->itree.last = start - 1;
interval_tree_insert(&p->itree, &pageflags_root);
pageflags_create(p_start, start - 1, p_flags);
g_free_rcu(p, rcu);
if (last < p_last) {
if (merge_flags & PAGE_VALID) {
@@ -393,11 +396,11 @@ static bool pageflags_set_clear(vaddr start, vaddr last,
}
if (last < p_last) {
interval_tree_remove(&p->itree, &pageflags_root);
p->itree.start = last + 1;
interval_tree_insert(&p->itree, &pageflags_root);
pageflags_create(last + 1, p_last, p_flags);
if (merge_flags & PAGE_VALID) {
pageflags_create(start, last, merge_flags);
}
g_free_rcu(p, rcu);
} else {
if (merge_flags & PAGE_VALID) {
p->flags = merge_flags;
@@ -418,8 +421,8 @@ static bool pageflags_set_clear(vaddr start, vaddr last,
if (set_flags == p_flags) {
if (start < p_start) {
interval_tree_remove(&p->itree, &pageflags_root);
p->itree.start = start;
interval_tree_insert(&p->itree, &pageflags_root);
pageflags_create(start, p_last, p_flags);
g_free_rcu(p, rcu);
}
if (p_last < last) {
start = p_last + 1;
@@ -431,8 +434,8 @@ static bool pageflags_set_clear(vaddr start, vaddr last,
/* Maybe split out head and/or tail ranges with the original flags. */
interval_tree_remove(&p->itree, &pageflags_root);
if (p_start < start) {
p->itree.last = start - 1;
interval_tree_insert(&p->itree, &pageflags_root);
pageflags_create(p_start, start - 1, p_flags);
g_free_rcu(p, rcu);
if (p_last < last) {
goto restart;
@@ -441,8 +444,8 @@ static bool pageflags_set_clear(vaddr start, vaddr last,
pageflags_create(last + 1, p_last, p_flags);
}
} else if (last < p_last) {
p->itree.start = last + 1;
interval_tree_insert(&p->itree, &pageflags_root);
pageflags_create(last + 1, p_last, p_flags);
g_free_rcu(p, rcu);
} else {
g_free_rcu(p, rcu);
goto restart;
@@ -504,6 +507,8 @@ bool page_check_range(vaddr start, vaddr len, int flags)
return false; /* wrap around */
}
RCU_READ_LOCK_GUARD();
locked = have_mmap_lock();
while (true) {
PageFlagsNode *p = pageflags_find(start, last);
@@ -768,7 +773,7 @@ static int probe_access_internal(CPUArchState *env, vaddr addr,
if (page_flags & acc_flag) {
if (access_type != MMU_INST_FETCH
&& cpu_plugin_mem_cbs_enabled(env_cpu(env))) {
return TLB_MMIO;
return TLB_FORCE_SLOW;
}
return 0; /* success */
}
@@ -803,7 +808,7 @@ void *probe_access(CPUArchState *env, vaddr addr, int size,
g_assert(-(addr | TARGET_PAGE_MASK) >= size);
flags = probe_access_internal(env, addr, size, access_type, false, ra);
g_assert((flags & ~TLB_MMIO) == 0);
g_assert((flags & ~TLB_FORCE_SLOW) == 0);
return size ? g2h_vaddr(env_cpu(env), addr) : NULL;
}
+7
View File
@@ -202,6 +202,13 @@ virgl_cmd_submit_3d(VuGpu *g,
VUGPU_FILL_CMD(cs);
if (cs.size > VIRTIO_GPU_MAX_CMD_SUBMIT_SIZE) {
g_critical("%s: command buffer too large (%u)",
__func__, cs.size);
cmd->error = VIRTIO_GPU_RESP_ERR_INVALID_PARAMETER;
return;
}
buf = g_malloc(cs.size);
s = iov_to_buf(cmd->elem.out_sg, cmd->elem.out_num,
sizeof(cs), buf, cs.size);
+9
View File
@@ -22,6 +22,7 @@
#include "qemu/queue.h"
#include "qemu/iov.h"
#include "qemu/bswap.h"
#include "qemu/units.h"
#include "vugbm.h"
typedef enum VhostUserGpuRequest {
@@ -163,6 +164,14 @@ struct virtio_gpu_ctrl_command {
QTAILQ_ENTRY(virtio_gpu_ctrl_command) next;
};
/*
* With 4 KiB pages and QEMU's VIRTQUEUE_MAX_SIZE (1024) mapped-iov
* limit, the largest inline command is ~4 MiB. Cap submit_3d
* allocations to this value to prevent a malicious guest from
* triggering an OOM abort via an inflated cs.size field.
*/
#define VIRTIO_GPU_MAX_CMD_SUBMIT_SIZE (4 * MiB)
#define VUGPU_FILL_CMD(out) do { \
size_t vugpufillcmd_s_ = \
iov_to_buf(cmd->elem.out_sg, cmd->elem.out_num, 0, \
+2 -1
View File
@@ -46,7 +46,8 @@ int qcrypto_get_x509_cert_fingerprint(uint8_t *cert, size_t size,
return -1;
}
if (gnutls_x509_crt_init(&crt) < 0) {
ret = gnutls_x509_crt_init(&crt);
if (ret < 0) {
error_setg(errp, "Unable to initialize certificate: %s",
gnutls_strerror(ret));
return -1;
+11
View File
@@ -81,6 +81,11 @@ typedef struct ExtendedOps {
#define V9FS_SEC_MASK 0x0000003C
/*
* Limits the maximum amount of simultaneously open xattr FIDs to prevent
* host memory exhaustion (as each xattr FID contains a xattr value buffer).
*/
#define V9FS_MAX_XATTR_DEFAULT 1024
typedef struct FileOperations FileOperations;
typedef struct XattrOperations XattrOperations;
@@ -96,6 +101,8 @@ typedef struct FsDriverEntry {
FsThrottle fst;
mode_t fmode;
mode_t dmode;
/* temporary storage for parse_opts only */
uint32_t max_xattr;
} FsDriverEntry;
struct FsContext {
@@ -109,6 +116,10 @@ struct FsContext {
void *private;
mode_t fmode;
mode_t dmode;
/* max. amount of simultaneously open xattr FIDs */
uint32_t xattr_fid_limit;
/* current amount of open xattr FIDs */
uint32_t xattr_fid_count;
};
struct V9fsPath {
+6
View File
@@ -46,6 +46,9 @@ static QemuOptsList qemu_fsdev_opts = {
}, {
.name = "dmode",
.type = QEMU_OPT_NUMBER,
}, {
.name = "max_xattr",
.type = QEMU_OPT_NUMBER,
},
THROTTLE_OPTS,
@@ -92,6 +95,9 @@ static QemuOptsList qemu_virtfs_opts = {
}, {
.name = "dmode",
.type = QEMU_OPT_NUMBER,
}, {
.name = "max_xattr",
.type = QEMU_OPT_NUMBER,
},
{ /*End of list */ }
+1 -1
View File
@@ -45,7 +45,7 @@ typedef struct FsDriverListEntry {
static QTAILQ_HEAD(, FsDriverListEntry) fsdriver_entries =
QTAILQ_HEAD_INITIALIZER(fsdriver_entries);
#define COMMON_FS_DRIVER_OPTIONS "id", "fsdriver", "readonly"
#define COMMON_FS_DRIVER_OPTIONS "id", "fsdriver", "readonly", "max_xattr"
static FsDriverTable FsDrivers[] = {
{
+13 -1
View File
@@ -775,8 +775,11 @@ static int local_fid_fd(int fid_type, V9fsFidOpenState *fs)
{
if (fid_type == P9_FID_DIR) {
return dirfd(fs->dir.stream);
} else {
} else if (fid_type == P9_FID_FILE) {
return fs->fd;
} else {
errno = EBADF;
return -1;
}
}
@@ -1527,6 +1530,15 @@ static int local_parse_opts(QemuOpts *opts, FsDriverEntry *fse, Error **errp)
const char *path = qemu_opt_get(opts, "path");
const char *multidevs = qemu_opt_get(opts, "multidevs");
uint64_t val = qemu_opt_get_number(opts, "max_xattr",
V9FS_MAX_XATTR_DEFAULT);
if (val > UINT32_MAX) {
error_setg(errp, "max_xattr value '%s' too large",
qemu_opt_get(opts, "max_xattr"));
return -1;
}
fse->max_xattr = val;
if (!sec_model) {
error_setg(errp, "security_model property not set");
error_append_security_model_hint(errp);
+47 -4
View File
@@ -25,6 +25,8 @@
#include "qemu/rcu_queue.h"
#include "qemu/cutils.h"
#include "system/qtest.h"
#include "qapi/error.h"
#include "qemu/option.h"
/* Root node for synth file system */
static V9fsSynthNode synth_root = {
@@ -475,15 +477,15 @@ static int synth_lsetxattr(FsContext *ctx, V9fsPath *path,
const char *name, void *value,
size_t size, int flags)
{
errno = ENOTSUP;
return -1;
/* pretend it worked */
return 0;
}
static int synth_lremovexattr(FsContext *ctx,
V9fsPath *path, const char *name)
{
errno = ENOTSUP;
return -1;
/* pretend it worked */
return 0;
}
static int synth_name_to_path(FsContext *ctx, V9fsPath *dir_path,
@@ -563,6 +565,19 @@ static ssize_t v9fs_synth_qtest_flush_write(void *buf, int len, off_t offset,
return 1;
}
/* transmits internal xattr counter to client */
static ssize_t v9fs_synth_read_xattr_count(void *buf, int len, off_t offset,
void *arg)
{
FsContext *ctx = arg;
size_t local_count = ctx->xattr_fid_count;
if (len < (int)sizeof(size_t)) {
return -ENOSPC;
}
memcpy(buf, &local_count, sizeof(size_t));
return sizeof(size_t);
}
static int synth_init(FsContext *ctx, Error **errp)
{
QLIST_INIT(&synth_root.child);
@@ -624,17 +639,45 @@ static int synth_init(FsContext *ctx, Error **errp)
g_free(name);
}
}
/* Directory for internal statistic queries */
{
V9fsSynthNode *stat_dir = NULL;
ret = qemu_v9fs_synth_mkdir(NULL, 0755, "stat", &stat_dir);
assert(!ret);
/* File for internal xattr count query */
ret = qemu_v9fs_synth_add_file(stat_dir, 0444, "xattr_count",
v9fs_synth_read_xattr_count,
NULL, ctx);
assert(!ret);
}
}
return 0;
}
static int synth_parse_opts(QemuOpts *opts, FsDriverEntry *fse, Error **errp)
{
uint64_t val = qemu_opt_get_number(opts, "max_xattr",
V9FS_MAX_XATTR_DEFAULT);
if (val > UINT32_MAX) {
error_setg(errp, "max_xattr value '%s' too large",
qemu_opt_get(opts, "max_xattr"));
return -1;
}
fse->max_xattr = val;
return 0;
}
static bool synth_has_valid_file_handle(int fid_type, V9fsFidOpenState *fs)
{
return false;
}
FileOperations synth_ops = {
.parse_opts = synth_parse_opts,
.init = synth_init,
.lstat = synth_lstat,
.readlink = synth_readlink,
+111 -2
View File
@@ -265,6 +265,31 @@ static size_t v9fs_string_size(V9fsString *str)
return str->size;
}
static int xattr_fid_count_inc(V9fsPDU *pdu)
{
V9fsState *s = pdu->s;
if (s->ctx.xattr_fid_limit > 0 &&
s->ctx.xattr_fid_count >= s->ctx.xattr_fid_limit) {
error_report_once("9pfs: xattr_fid_count limit exceeded "
"(configurable by option 'max_xattr').");
return -ENOSPC;
}
s->ctx.xattr_fid_count++;
return 0;
}
static void xattr_fid_count_decr(V9fsPDU *pdu)
{
V9fsState *s = pdu->s;
if (s->ctx.xattr_fid_count > 0) {
s->ctx.xattr_fid_count--;
} else {
error_report_once("9pfs: xattr_fid_count underflow detected");
}
}
/*
* returns 0 if fid got re-opened, 1 if not, < 0 on error
*/
@@ -397,6 +422,7 @@ static int coroutine_fn free_fid(V9fsPDU *pdu, V9fsFidState *fidp)
}
} else if (fidp->fid_type == P9_FID_XATTR) {
retval = v9fs_xattr_fid_clunk(pdu, fidp);
xattr_fid_count_decr(pdu);
}
v9fs_path_free(&fidp->path);
g_free(fidp);
@@ -634,6 +660,14 @@ static void coroutine_fn virtfs_reset(V9fsPDU *pdu)
fidp->clunked = true;
put_fid(pdu, fidp);
}
/*
* Explicitly reset the xattr FID counter.
*
* free_fid() already decrements the counter for each P9_FID_XATTR, so the
* counter should already be zero, hence this is just a defensive measure.
*/
s->ctx.xattr_fid_count = 0;
}
#define P9_QID_TYPE_DIR 0x80
@@ -1469,6 +1503,16 @@ static void coroutine_fn v9fs_version(void *opaque)
goto out;
}
/* cap msize to transport's theoretical limit */
if (s->transport->msize_limit) {
size_t limit = s->transport->msize_limit(s);
if (s->msize > limit) {
s->msize = limit;
warn_report_once("9p: client msize capped to %zu (transport limit)",
limit);
}
}
/* 8192 is the default msize of Linux clients */
if (s->msize <= 8192 && !(s->ctx.export_flags & V9FS_NO_PERF_WARN)) {
warn_report_once(
@@ -2247,10 +2291,15 @@ static void coroutine_fn v9fs_fsync(void *opaque)
err = -ENOENT;
goto out_nofid;
}
if (!fid_has_valid_file_handle(pdu->s, fidp)) {
err = -EBADF;
goto out;
}
err = v9fs_co_fsync(pdu, fidp, datasync);
if (!err) {
err = offset;
}
out:
put_fid(pdu, fidp);
out_nofid:
pdu_complete(pdu, err);
@@ -2655,6 +2704,7 @@ static void coroutine_fn v9fs_readdir(void *opaque)
uint32_t max_count;
V9fsPDU *pdu = opaque;
V9fsState *s = pdu->s;
size_t max_resp_sz;
retval = pdu_unmarshal(pdu, offset, "dqd", &fid,
&initial_offset, &max_count);
@@ -2663,9 +2713,28 @@ static void coroutine_fn v9fs_readdir(void *opaque)
}
trace_v9fs_readdir(pdu->tag, pdu->id, fid, initial_offset, max_count);
max_resp_sz = s->msize;
/*
* Constrain max_count to transport's current, actual response buffer size.
* A bad client might provide a response buffer < msize.
*/
if (s->transport->response_buffer_size) {
size_t buf_size = s->transport->response_buffer_size(pdu);
if (max_resp_sz > buf_size) {
max_resp_sz = buf_size;
}
}
/* Enough space for a R_readdir header: size[4] Rreaddir tag[2] count[4] */
if (max_count > s->msize - 11) {
max_count = s->msize - 11;
if (max_resp_sz > 11) {
max_resp_sz -= 11;
} else {
max_resp_sz = 0;
}
if (max_count > max_resp_sz) {
max_count = max_resp_sz;
warn_report_once(
"9p: bad client: T_readdir with count > msize - 11"
);
@@ -3584,6 +3653,10 @@ static void coroutine_fn v9fs_wstat(void *opaque)
}
/* do we need to sync the file? */
if (donttouch_stat(&v9stat)) {
if (!fid_has_valid_file_handle(s, fidp)) {
err = -EBADF;
goto out;
}
err = v9fs_co_fsync(pdu, fidp, 0);
goto out;
}
@@ -3852,6 +3925,10 @@ static void coroutine_fn v9fs_lock(void *opaque)
err = -ENOENT;
goto out_nofid;
}
if (!fid_has_valid_file_handle(pdu->s, fidp)) {
err = -EBADF;
goto out;
}
err = v9fs_co_fstat(pdu, fidp, &stbuf);
if (err < 0) {
goto out;
@@ -3897,6 +3974,10 @@ static void coroutine_fn v9fs_getlock(void *opaque)
err = -ENOENT;
goto out_nofid;
}
if (!fid_has_valid_file_handle(pdu->s, fidp)) {
err = -EBADF;
goto out;
}
err = v9fs_co_fstat(pdu, fidp, &stbuf);
if (err < 0) {
goto out;
@@ -4015,6 +4096,14 @@ static void coroutine_fn v9fs_xattrwalk(void *opaque)
clunk_fid(s, xattr_fidp->fid);
goto out;
}
/* Check xattr FID limit */
err = xattr_fid_count_inc(pdu);
if (err < 0) {
clunk_fid(s, xattr_fidp->fid);
goto out;
}
/*
* Read the xattr value
*/
@@ -4022,6 +4111,7 @@ static void coroutine_fn v9fs_xattrwalk(void *opaque)
xattr_fidp->fid_type = P9_FID_XATTR;
xattr_fidp->fs.xattr.xattrwalk_fid = true;
xattr_fidp->fs.xattr.value = g_malloc0(size);
if (size) {
err = v9fs_co_llistxattr(pdu, &xattr_fidp->path,
xattr_fidp->fs.xattr.value,
@@ -4048,6 +4138,14 @@ static void coroutine_fn v9fs_xattrwalk(void *opaque)
clunk_fid(s, xattr_fidp->fid);
goto out;
}
/* Check xattr FID limit */
err = xattr_fid_count_inc(pdu);
if (err < 0) {
clunk_fid(s, xattr_fidp->fid);
goto out;
}
/*
* Read the xattr value
*/
@@ -4055,6 +4153,7 @@ static void coroutine_fn v9fs_xattrwalk(void *opaque)
xattr_fidp->fid_type = P9_FID_XATTR;
xattr_fidp->fs.xattr.xattrwalk_fid = true;
xattr_fidp->fs.xattr.value = g_malloc0(size);
if (size) {
err = v9fs_co_lgetxattr(pdu, &xattr_fidp->path,
&name, xattr_fidp->fs.xattr.value,
@@ -4156,6 +4255,12 @@ static void coroutine_fn v9fs_xattrcreate(void *opaque)
goto out_put_fid;
}
/* Check xattr FID limit */
err = xattr_fid_count_inc(pdu);
if (err < 0) {
goto out_put_fid;
}
/* Make the file fid point to xattr */
xattr_fidp = file_fidp;
xattr_fidp->fid_type = P9_FID_XATTR;
@@ -4417,6 +4522,10 @@ int v9fs_device_realize_common(V9fsState *s, const V9fsTransport *t,
s->reclaiming = false;
/* init xattr FID limit from fsdev config */
s->ctx.xattr_fid_limit = fse->max_xattr;
s->ctx.xattr_fid_count = 0;
rc = 0;
out:
if (rc) {
+2
View File
@@ -481,6 +481,8 @@ struct V9fsTransport {
void (*init_out_iov_from_pdu)(V9fsPDU *pdu, struct iovec **piov,
unsigned int *pniov, size_t size);
void (*push_and_notify)(V9fsPDU *pdu);
size_t (*msize_limit)(V9fsState *s);
size_t (*response_buffer_size)(V9fsPDU *pdu);
};
#endif
+17
View File
@@ -192,12 +192,29 @@ static void virtio_init_out_iov_from_pdu(V9fsPDU *pdu, struct iovec **piov,
*pniov = elem->out_num;
}
static size_t virtio_9p_msize_limit(V9fsState *s)
{
const size_t guestPageSize = 4096;
return (VIRTQUEUE_MAX_SIZE - 2) * guestPageSize;
}
static size_t virtio_9p_response_buffer_size(V9fsPDU *pdu)
{
V9fsState *s = pdu->s;
V9fsVirtioState *v = container_of(s, V9fsVirtioState, state);
VirtQueueElement *elem = v->elems[pdu->idx];
return iov_size(elem->in_sg, elem->in_num);
}
static const V9fsTransport virtio_9p_transport = {
.pdu_vmarshal = virtio_pdu_vmarshal,
.pdu_vunmarshal = virtio_pdu_vunmarshal,
.init_in_iov_from_pdu = virtio_init_in_iov_from_pdu,
.init_out_iov_from_pdu = virtio_init_out_iov_from_pdu,
.push_and_notify = virtio_9p_push_and_notify,
.msize_limit = virtio_9p_msize_limit,
.response_buffer_size = virtio_9p_response_buffer_size,
};
static void virtio_9p_device_realize(DeviceState *dev, Error **errp)
+31
View File
@@ -250,12 +250,43 @@ static void xen_9pfs_push_and_notify(V9fsPDU *pdu)
qemu_bh_schedule(ring->bh);
}
static size_t xen_9p_msize_limit(V9fsState *s)
{
Xen9pfsDev *xen_9pfs = container_of(s, Xen9pfsDev, state);
size_t limit;
int i;
if (!xen_9pfs->num_rings) {
return 0;
}
limit = XEN_FLEX_RING_SIZE(xen_9pfs->rings[0].ring_order);
for (i = 1; i < xen_9pfs->num_rings; i++) {
limit = MIN(limit, XEN_FLEX_RING_SIZE(xen_9pfs->rings[i].ring_order));
}
return limit;
}
static size_t xen_9pfs_response_buffer_size(V9fsPDU *pdu)
{
Xen9pfsDev *priv = container_of(pdu->s, Xen9pfsDev, state);
Xen9pfsRing *ring = &priv->rings[pdu->tag % priv->num_rings];
struct iovec in_sg[2];
int num;
xen_9pfs_in_sg(ring, in_sg, &num, pdu->idx, 0);
return iov_size(in_sg, num);
}
static const V9fsTransport xen_9p_transport = {
.pdu_vmarshal = xen_9pfs_pdu_vmarshal,
.pdu_vunmarshal = xen_9pfs_pdu_vunmarshal,
.init_in_iov_from_pdu = xen_9pfs_init_in_iov_from_pdu,
.init_out_iov_from_pdu = xen_9pfs_init_out_iov_from_pdu,
.push_and_notify = xen_9pfs_push_and_notify,
.msize_limit = xen_9p_msize_limit,
.response_buffer_size = xen_9pfs_response_buffer_size,
};
static int xen_9pfs_init(struct XenLegacyDevice *xendev)
+2 -2
View File
@@ -2115,10 +2115,10 @@ void build_spcr(GArray *table_data, BIOSLinker *linker,
build_append_int_noprefix(table_data, f->stop_bits, 1);
/* Flow Control */
build_append_int_noprefix(table_data, f->flow_control, 1);
/* Language */
build_append_int_noprefix(table_data, f->language, 1);
/* Terminal Type */
build_append_int_noprefix(table_data, f->terminal_type, 1);
/* Language */
build_append_int_noprefix(table_data, f->language, 1);
/* PCI Device ID */
build_append_int_noprefix(table_data, f->pci_device_id, 2);
/* PCI Vendor ID */
+1 -1
View File
@@ -492,7 +492,7 @@ static void npcm7xx_realize(DeviceState *dev, Error **errp)
/* CPUs */
for (i = 0; i < nc->num_cpus; i++) {
object_property_set_int(OBJECT(&s->cpu[i]), "reset-cbar",
NPCM7XX_GIC_CPU_IF_ADDR, &error_abort);
NPCM7XX_CPUP_BA, &error_abort);
object_property_set_bool(OBJECT(&s->cpu[i]), "reset-hivecs", true,
&error_abort);
+1 -1
View File
@@ -1528,7 +1528,7 @@ static int smmuv3_cmdq_consume(SMMUv3State *s, Error **errp)
{
SMMUDevice *sdev = smmu_find_sdev(bs, CMD_SID(&cmd));
if (!sdev || !s->ats) {
if (!sdev || !smmuv3_ats_enabled(s)) {
trace_smmuv3_unhandled_cmd(type);
break;
}
+6 -3
View File
@@ -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));
+7 -27
View File
@@ -344,22 +344,16 @@ void virtio_serial_throttle_port(VirtIOSerialPort *port, bool throttle)
}
/* Guest wants to notify us of some event */
static void handle_control_message(VirtIOSerial *vser, void *buf, size_t len)
static void handle_control_message(VirtIOSerial *vser,
struct virtio_console_control *gcpkt)
{
VirtIODevice *vdev = VIRTIO_DEVICE(vser);
struct VirtIOSerialPort *port;
VirtIOSerialPortClass *vsc;
struct virtio_console_control cpkt, *gcpkt;
struct virtio_console_control cpkt;
uint8_t *buffer;
size_t buffer_len;
gcpkt = buf;
if (len < sizeof(cpkt)) {
/* The guest sent an invalid control packet */
return;
}
cpkt.event = virtio_lduw_p(vdev, &gcpkt->event);
cpkt.value = virtio_lduw_p(vdev, &gcpkt->value);
@@ -457,41 +451,27 @@ static void control_in(VirtIODevice *vdev, VirtQueue *vq)
static void control_out(VirtIODevice *vdev, VirtQueue *vq)
{
struct virtio_console_control cpkt;
VirtQueueElement *elem;
VirtIOSerial *vser;
uint8_t *buf;
size_t len;
vser = VIRTIO_SERIAL(vdev);
len = 0;
buf = NULL;
for (;;) {
size_t cur_len;
elem = virtqueue_pop(vq, sizeof(VirtQueueElement));
if (!elem) {
break;
}
cur_len = iov_size(elem->out_sg, elem->out_num);
/*
* Allocate a new buf only if we didn't have one previously or
* if the size of the buf differs
*/
if (cur_len > len) {
g_free(buf);
buf = g_malloc(cur_len);
len = cur_len;
len = iov_to_buf(elem->out_sg, elem->out_num, 0, &cpkt, sizeof(cpkt));
if (len == sizeof(cpkt)) {
handle_control_message(vser, &cpkt);
}
iov_to_buf(elem->out_sg, elem->out_num, 0, buf, cur_len);
handle_control_message(vser, buf, cur_len);
virtqueue_push(vq, elem, 0);
g_free(elem);
}
g_free(buf);
virtio_notify(vdev, vq);
}
+8 -1
View File
@@ -157,7 +157,14 @@ Clock *qdev_alias_clock(DeviceState *dev, const char *name,
DeviceState *alias_dev, const char *alias_name)
{
NamedClockList *ncl = qdev_get_clocklist(dev, name);
Clock *clk = ncl->clock;
Clock *clk;
if (!ncl) {
error_report("Can not find clock '%s' for device type '%s'",
name, object_get_typename(OBJECT(dev)));
abort();
}
clk = ncl->clock;
ncl = qdev_init_clocklist(alias_dev, alias_name, true, ncl->output, clk);
+2
View File
@@ -1032,8 +1032,10 @@ static void ati_mm_write(void *opaque, hwaddr addr,
s->host_data.acc[s->host_data.next++] = data;
if (addr == HOST_DATA_LAST) {
ati_host_data_finish(s);
s->host_data.next = 0;
} else if (s->host_data.next >= 4) {
ati_host_data_flush(s);
s->host_data.next = 0;
}
break;
default:
+5 -1
View File
@@ -377,6 +377,11 @@ bool ati_host_data_flush(ATIVGAState *s)
setup_2d_blt_ctx(s, &ctx);
if (!ctx.bpp) {
qemu_log_mask(LOG_GUEST_ERROR,
"host_data_blt: invalid bpp from datatype\n");
return false;
}
if (ctx.bpp == 24) {
qemu_log_mask(LOG_UNIMP,
"host_data_blt: unsupported in 24 bits mode\n");
@@ -452,7 +457,6 @@ bool ati_host_data_flush(ATIVGAState *s)
}
/* Track state of the overall blit for use by the next flush */
s->host_data.next = 0;
s->host_data.row = row;
s->host_data.col = col;
if (s->host_data.row >= ctx.dst.height) {
+20 -12
View File
@@ -217,7 +217,8 @@ void qxl_render_update_area_done(PCIQXLDevice *qxl, QXLCookie *cookie)
}
static void qxl_unpack_chunks(void *dest, size_t size, PCIQXLDevice *qxl,
QXLDataChunk *chunk, uint32_t group_id)
QXLDataChunk *chunk, uint32_t group_id,
uint32_t chunk_data_size)
{
uint32_t max_chunks = 32;
size_t offset = 0;
@@ -225,22 +226,21 @@ static void qxl_unpack_chunks(void *dest, size_t size, PCIQXLDevice *qxl,
QXLPHYSICAL next_chunk_phys = 0;
for (;;) {
bytes = MIN(size - offset, chunk->data_size);
bytes = MIN(size - offset, chunk_data_size);
memcpy(dest + offset, chunk->data, bytes);
offset += bytes;
if (offset == size) {
return;
}
next_chunk_phys = chunk->next_chunk;
/* fist time, only get the next chunk's data size */
chunk = qxl_phys2virt(qxl, next_chunk_phys, group_id,
sizeof(QXLDataChunk));
if (!chunk) {
return;
}
/* second time, check data size and get data */
chunk_data_size = chunk->data_size;
chunk = qxl_phys2virt(qxl, next_chunk_phys, group_id,
sizeof(QXLDataChunk) + chunk->data_size);
sizeof(QXLDataChunk) + chunk_data_size);
if (!chunk) {
return;
}
@@ -252,7 +252,7 @@ static void qxl_unpack_chunks(void *dest, size_t size, PCIQXLDevice *qxl,
}
static QEMUCursor *qxl_cursor(PCIQXLDevice *qxl, QXLCursor *cursor,
uint32_t group_id)
uint32_t group_id, uint32_t chunk_data_size)
{
QEMUCursor *c;
uint8_t *and_mask, *xor_mask;
@@ -272,9 +272,11 @@ static QEMUCursor *qxl_cursor(PCIQXLDevice *qxl, QXLCursor *cursor,
case SPICE_CURSOR_TYPE_MONO:
/* Assume that the full cursor is available in a single chunk. */
size = 2 * cursor_get_mono_bpl(c) * c->height;
if (size != cursor->data_size) {
fprintf(stderr, "%s: bad monochrome cursor %ux%u with size %u\n",
__func__, c->width, c->height, cursor->data_size);
if (size != cursor->data_size || chunk_data_size < size) {
qxl_set_guest_bug(qxl, "%s: bad monochrome cursor %ux%u"
" data_size %u chunk_size %u",
__func__, c->width, c->height,
cursor->data_size, chunk_data_size);
goto fail;
}
and_mask = cursor->chunk.data;
@@ -286,7 +288,8 @@ static QEMUCursor *qxl_cursor(PCIQXLDevice *qxl, QXLCursor *cursor,
break;
case SPICE_CURSOR_TYPE_ALPHA:
size = sizeof(uint32_t) * c->width * c->height;
qxl_unpack_chunks(c->data, size, qxl, &cursor->chunk, group_id);
qxl_unpack_chunks(c->data, size, qxl, &cursor->chunk, group_id,
chunk_data_size);
if (qxl->debug > 2) {
cursor_print_ascii_art(c, "qxl/alpha");
}
@@ -323,19 +326,23 @@ int qxl_render_cursor(PCIQXLDevice *qxl, QXLCommandExt *ext)
}
switch (cmd->type) {
case QXL_CURSOR_SET:
{
uint32_t chunk_data_size;
/* First read the QXLCursor to get QXLDataChunk::data_size ... */
cursor = qxl_phys2virt(qxl, cmd->u.set.shape, ext->group_id,
sizeof(QXLCursor));
if (!cursor) {
return 1;
}
chunk_data_size = cursor->chunk.data_size;
/* Then read including the chunked data following QXLCursor. */
cursor = qxl_phys2virt(qxl, cmd->u.set.shape, ext->group_id,
sizeof(QXLCursor) + cursor->chunk.data_size);
sizeof(QXLCursor) + chunk_data_size);
if (!cursor) {
return 1;
}
c = qxl_cursor(qxl, cursor, ext->group_id);
c = qxl_cursor(qxl, cursor, ext->group_id, chunk_data_size);
if (c == NULL) {
c = cursor_builtin_left_ptr();
}
@@ -349,6 +356,7 @@ int qxl_render_cursor(PCIQXLDevice *qxl, QXLCommandExt *ext)
qemu_mutex_unlock(&qxl->ssd.lock);
qemu_bh_schedule(qxl->ssd.cursor_bh);
break;
}
case QXL_CURSOR_MOVE:
qemu_mutex_lock(&qxl->ssd.lock);
qxl->ssd.mouse_x = cmd->u.position.x;
+1 -1
View File
@@ -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;
+55 -9
View File
@@ -571,6 +571,25 @@ static uint32_t get_local_mem_size_index(uint32_t size)
return index;
}
static void set_new_local_mem_size_index(SM501State *s, uint32_t idx)
{
/*
* Update local_mem_size_index on guest write. We don't allow this
* to be set to larger than the actual RAM size. (The guest will
* still read back the SYSTEM_CONTROL.Size bits that it wrote.)
*/
if (idx < ARRAY_SIZE(sm501_mem_local_size) &&
sm501_mem_local_size[idx] <= memory_region_size(&s->local_mem_region)) {
s->local_mem_size_index = idx;
return;
}
qemu_log_mask(LOG_GUEST_ERROR,
"sm501: Guest set DRAM_CONTROL.Size to 0x%x but "
"local memory is not that large\n",
idx);
/* Don't change the effective size, leave it as whatever it was */
}
static ram_addr_t get_fb_addr(SM501State *s, int crt)
{
return (crt ? s->dc_crt_fb_addr : s->dc_panel_fb_addr) & 0x3FFFFF0;
@@ -682,6 +701,28 @@ static inline void hwc_invalidate(SM501State *s, int crt)
get_fb_addr(s, crt) + start, end - start);
}
static bool sm501_rect_outside_vram(SM501State *s, uint32_t base,
uint32_t x, uint32_t y,
uint32_t width, uint32_t height,
uint32_t pitch, uint32_t bypp)
{
/*
* Return true if the 2D area specified by the arguments is
* partially or completely outside the VRAM (a guest error)
*
* Limits on the input sizes mean we can't overflow as long as
* we do all the arithmetic at 64 bits.
*/
uint64_t rect_size, last_addr;
assert(x <= UINT16_MAX && y <= UINT16_MAX && height <= UINT16_MAX &&
pitch <= UINT16_MAX && bypp <= 8);
rect_size = (((uint64_t)y + height) * pitch + x + width) * bypp;
last_addr = base + rect_size;
return last_addr >= get_local_mem_size(s);
}
static void sm501_2d_operation(SM501State *s)
{
int cmd = (s->twoD_control >> 16) & 0x1F;
@@ -723,13 +764,16 @@ static void sm501_2d_operation(SM501State *s)
}
if (rtl) {
if (dst_x < (width - 1) || dst_y < (height - 1)) {
qemu_log_mask(LOG_GUEST_ERROR, "sm501: RTL op out of bounds\n");
return;
}
dst_x -= width - 1;
dst_y -= height - 1;
}
if (dst_base >= get_local_mem_size(s) ||
dst_base + (dst_x + width + (dst_y + height) * dst_pitch) * bypp >=
get_local_mem_size(s)) {
if (sm501_rect_outside_vram(s, dst_base, dst_x, dst_y, width, height,
dst_pitch, bypp)) {
qemu_log_mask(LOG_GUEST_ERROR, "sm501: 2D op dest is outside vram.\n");
return;
}
@@ -748,13 +792,16 @@ static void sm501_2d_operation(SM501State *s)
}
if (rtl) {
if (src_x < (width - 1) || src_y < (height - 1)) {
qemu_log_mask(LOG_GUEST_ERROR, "sm501: RTL op out of bounds\n");
return;
}
src_x -= width - 1;
src_y -= height - 1;
}
if (src_base >= get_local_mem_size(s) ||
src_base + (src_x + width + (src_y + height) * src_pitch) * bypp >=
get_local_mem_size(s)) {
if (sm501_rect_outside_vram(s, src_base, src_x, src_y, width, height,
src_pitch, bypp)) {
qemu_log_mask(LOG_GUEST_ERROR,
"sm501: 2D op src is outside vram.\n");
return;
@@ -962,7 +1009,7 @@ static uint64_t sm501_system_config_read(void *opaque, hwaddr addr,
ret = 0x050100A0;
break;
case SM501_DRAM_CONTROL:
ret = (s->dram_control & 0x07F107C0) | s->local_mem_size_index << 13;
ret = (s->dram_control & 0x07F1E7C0);
break;
case SM501_ARBTRTN_CONTROL:
ret = s->arbitration_control;
@@ -1021,8 +1068,7 @@ static void sm501_system_config_write(void *opaque, hwaddr addr,
s->gpio_63_32_control = value & 0xFF80FFFF;
break;
case SM501_DRAM_CONTROL:
s->local_mem_size_index = (value >> 13) & 0x7;
/* TODO : check validity of size change */
set_new_local_mem_size_index(s, (value >> 13) & 0x7);
s->dram_control &= 0x80000000;
s->dram_control |= value & 0x7FFFFFC3;
break;
+8
View File
@@ -351,6 +351,14 @@ rutabaga_cmd_submit_3d(VirtIOGPU *g,
VIRTIO_GPU_FILL_CMD(cs);
trace_virtio_gpu_cmd_ctx_submit(cs.hdr.ctx_id, cs.size);
if (cs.size > VIRTIO_GPU_MAX_CMD_SUBMIT_SIZE) {
qemu_log_mask(LOG_GUEST_ERROR,
"%s: command buffer too large (%u)\n",
__func__, cs.size);
cmd->error = VIRTIO_GPU_RESP_ERR_INVALID_PARAMETER;
return;
}
buf = g_new0(uint8_t, cs.size);
s = iov_to_buf(cmd->elem.out_sg, cmd->elem.out_num,
sizeof(cs), buf, cs.size);
+1
View File
@@ -143,6 +143,7 @@ void virtio_gpu_init_udmabuf(struct virtio_gpu_simple_resource *res)
}
virtio_gpu_remap_udmabuf(res);
if (!res->remapped) {
virtio_gpu_destroy_udmabuf(res);
return;
}
pdata = res->remapped;
+8
View File
@@ -608,6 +608,14 @@ static void virgl_cmd_submit_3d(VirtIOGPU *g,
VIRTIO_GPU_FILL_CMD(cs);
trace_virtio_gpu_cmd_ctx_submit(cs.hdr.ctx_id, cs.size);
if (cs.size > VIRTIO_GPU_MAX_CMD_SUBMIT_SIZE) {
qemu_log_mask(LOG_GUEST_ERROR,
"%s: command buffer too large (%u)\n",
__func__, cs.size);
cmd->error = VIRTIO_GPU_RESP_ERR_INVALID_PARAMETER;
return;
}
buf = g_malloc(cs.size);
s = iov_to_buf(cmd->elem.out_sg, cmd->elem.out_num,
sizeof(cs), buf, cs.size);
+22 -4
View File
@@ -674,6 +674,10 @@ static bool virtio_gpu_do_set_scanout(VirtIOGPU *g,
void *ptr = data + fb->offset;
rect = pixman_image_create_bits(fb->format, r->width, r->height,
ptr, fb->stride);
if (!rect) {
*error = VIRTIO_GPU_RESP_ERR_UNSPEC;
return false;
}
if (res->image) {
pixman_image_ref(res->image);
@@ -1349,8 +1353,15 @@ static int virtio_gpu_load(QEMUFile *f, void *opaque, size_t size,
return -EINVAL;
}
res->addrs = g_new(uint64_t, res->iov_cnt);
res->iov = g_new(struct iovec, res->iov_cnt);
res->addrs = g_try_new(uint64_t, res->iov_cnt);
res->iov = g_try_new(struct iovec, res->iov_cnt);
if (res->iov_cnt && (!res->addrs || !res->iov)) {
pixman_image_unref(res->image);
g_free(res->addrs);
g_free(res->iov);
g_free(res);
return -EINVAL;
}
/* read data */
for (i = 0; i < res->iov_cnt; i++) {
@@ -1424,8 +1435,15 @@ static int virtio_gpu_blob_load(QEMUFile *f, void *opaque, size_t size,
res->resource_id = resource_id;
res->blob_size = qemu_get_be32(f);
res->iov_cnt = qemu_get_be32(f);
res->addrs = g_new(uint64_t, res->iov_cnt);
res->iov = g_new(struct iovec, res->iov_cnt);
res->addrs = g_try_new(uint64_t, res->iov_cnt);
res->iov = g_try_new(struct iovec, res->iov_cnt);
if (res->iov_cnt && (!res->addrs || !res->iov)) {
g_free(res->addrs);
g_free(res->iov);
g_free(res);
return -EINVAL;
}
/* read data */
for (i = 0; i < res->iov_cnt; i++) {
+13
View File
@@ -407,6 +407,19 @@ static int i8257_dma_read_memory(IsaDma *obj, int nchan, void *buf, int pos,
hwaddr addr = ((r->pageh & 0x7f) << 24) | (r->page << 16) | r->now[ADDR];
if (i8257_is_verify_transfer(r)) {
/*
* If the device is expecting this verify operation then
* it won't care about the nonexistent data. But if it
* is expecting a real read (i.e. the guest has misprogrammed
* the DMA controller and the device) it's going to try to do
* something with the buffer contents. Give it zeroes.
* (It's not clear whether this is exactly what happens if
* you do this on real hardware. In practice no device QEMU
* emulates has a use for verify on a memory-read transfer,
* so we don't care beyond avoiding the guest being able to
* trigger the caller reading uninitialized data.)
*/
memset(buf, 0, len);
return len;
}
+2 -2
View File
@@ -4998,7 +4998,7 @@ static void vtd_cap_init(IntelIOMMUState *s)
{
X86IOMMUState *x86_iommu = X86_IOMMU_DEVICE(s);
s->cap = VTD_CAP_FRO | VTD_CAP_NFR | VTD_CAP_ND | VTD_ECAP_PT |
s->cap = VTD_CAP_FRO | VTD_CAP_NFR | VTD_CAP_ND |
VTD_CAP_MAMV | VTD_CAP_PSI | VTD_CAP_SSLPS | VTD_CAP_DRAIN |
VTD_CAP_ESRTPS | VTD_CAP_MGAW(s->aw_bits);
if (x86_iommu->dma_translation) {
@@ -5009,7 +5009,7 @@ static void vtd_cap_init(IntelIOMMUState *s)
s->cap |= VTD_CAP_SAGAW_48bit;
}
}
s->ecap = VTD_ECAP_QI | VTD_ECAP_IRO;
s->ecap = VTD_ECAP_QI | VTD_ECAP_IRO | VTD_ECAP_PT;
if (x86_iommu_ir_supported(x86_iommu)) {
s->ecap |= VTD_ECAP_IR | VTD_ECAP_MHMV;
+3
View File
@@ -740,6 +740,9 @@ static bool ahci_map_clb_address(AHCIDevice *ad)
static void ahci_unmap_clb_address(AHCIDevice *ad)
{
/* Cancel in-flight reads that would complete against a cleared cur_cmd. */
ide_cancel_dma_sync(ide_bus_active_if(&ad->port));
if (ad->lst == NULL) {
trace_ahci_unmap_clb_address_null(ad->hba, ad->port_no);
return;
+3 -3
View File
@@ -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)
+14 -10
View File
@@ -103,7 +103,7 @@ static void edu_lower_irq(EduState *edu, uint32_t val)
}
}
static void edu_check_range(uint64_t xfer_start, uint64_t xfer_size,
static bool edu_check_range(uint64_t xfer_start, uint64_t xfer_size,
uint64_t dma_start, uint64_t dma_size)
{
uint64_t xfer_end = xfer_start + xfer_size;
@@ -115,13 +115,15 @@ static void edu_check_range(uint64_t xfer_start, uint64_t xfer_size,
*/
if (dma_end >= dma_start && xfer_end >= xfer_start &&
xfer_start >= dma_start && xfer_end <= dma_end) {
return;
return true;
}
qemu_log_mask(LOG_GUEST_ERROR,
"EDU: DMA range 0x%016"PRIx64"-0x%016"PRIx64
" out of bounds (0x%016"PRIx64"-0x%016"PRIx64")!",
xfer_start, xfer_end - 1, dma_start, dma_end - 1);
return false;
}
static dma_addr_t edu_clamp_addr(const EduState *edu, dma_addr_t addr)
@@ -148,16 +150,18 @@ static void edu_dma_timer(void *opaque)
if (EDU_DMA_DIR(edu->dma.cmd) == EDU_DMA_FROM_PCI) {
uint64_t dst = edu->dma.dst;
edu_check_range(dst, edu->dma.cnt, DMA_START, DMA_SIZE);
dst -= DMA_START;
pci_dma_read(&edu->pdev, edu_clamp_addr(edu, edu->dma.src),
edu->dma_buf + dst, edu->dma.cnt);
if (edu_check_range(dst, edu->dma.cnt, DMA_START, DMA_SIZE)) {
dst -= DMA_START;
pci_dma_read(&edu->pdev, edu_clamp_addr(edu, edu->dma.src),
edu->dma_buf + dst, edu->dma.cnt);
}
} else {
uint64_t src = edu->dma.src;
edu_check_range(src, edu->dma.cnt, DMA_START, DMA_SIZE);
src -= DMA_START;
pci_dma_write(&edu->pdev, edu_clamp_addr(edu, edu->dma.dst),
edu->dma_buf + src, edu->dma.cnt);
if (edu_check_range(src, edu->dma.cnt, DMA_START, DMA_SIZE)) {
src -= DMA_START;
pci_dma_write(&edu->pdev, edu_clamp_addr(edu, edu->dma.dst),
edu->dma_buf + src, edu->dma.cnt);
}
}
edu->dma.cmd &= ~EDU_DMA_RUN;
+6
View File
@@ -938,6 +938,9 @@ static void ivshmem_exit(PCIDevice *dev)
IVShmemState *s = IVSHMEM_COMMON(dev);
int i;
qemu_chr_fe_set_handlers(&s->server_chr,
NULL, NULL, NULL, NULL, NULL, NULL, true);
migrate_del_blocker(&s->migration_blocker);
if (memory_region_is_mapped(s->ivshmem_bar2)) {
@@ -966,6 +969,8 @@ static void ivshmem_exit(PCIDevice *dev)
close_peer_eventfds(s, i);
}
g_free(s->peers);
s->peers = NULL;
s->nb_peers = 0;
}
if (ivshmem_has_feature(s, IVSHMEM_MSI)) {
@@ -973,6 +978,7 @@ static void ivshmem_exit(PCIDevice *dev)
}
g_free(s->msi_vectors);
s->msi_vectors = NULL;
}
static int ivshmem_pre_load(void *opaque)
+27 -4
View File
@@ -53,6 +53,27 @@ static uint64_t stm32_rcc_read(void *opaque, hwaddr addr, unsigned int size)
return value;
}
static int reg_offset_to_irq_offset(hwaddr addr)
{
/*
* The reset and enable registers aren't all consecutive. In getting the
* irq index from the register offset, we need to account for the gap
* between the AHB regs and the APB regs.
*/
switch (addr) {
case STM32_RCC_AHB1_RSTR ... STM32_RCC_AHB3_RSTR:
return ((addr - STM32_RCC_AHB1_RSTR) / 4) * 32;
case STM32_RCC_APB1_RSTR ... STM32_RCC_APB2_RSTR:
return ((addr - STM32_RCC_APB1_RSTR) / 4) * 32 + STM32_RCC_N_AHB_IRQS;
case STM32_RCC_AHB1_ENR ... STM32_RCC_AHB3_ENR:
return ((addr - STM32_RCC_AHB1_ENR) / 4) * 32;
case STM32_RCC_APB1_ENR ... STM32_RCC_APB2_ENR:
return ((addr - STM32_RCC_APB1_ENR) / 4) * 32 + STM32_RCC_N_AHB_IRQS;
default:
g_assert_not_reached();
}
}
static void stm32_rcc_write(void *opaque, hwaddr addr,
uint64_t val64, unsigned int size)
{
@@ -69,11 +90,12 @@ static void stm32_rcc_write(void *opaque, hwaddr addr,
}
switch (addr) {
case STM32_RCC_AHB1_RSTR...STM32_RCC_APB2_RSTR:
case STM32_RCC_AHB1_RSTR ... STM32_RCC_AHB3_RSTR:
case STM32_RCC_APB1_RSTR ... STM32_RCC_APB2_RSTR:
prev_value = s->regs[addr / 4];
s->regs[addr / 4] = value;
irq_offset = ((addr - STM32_RCC_AHB1_RSTR) / 4) * 32;
irq_offset = reg_offset_to_irq_offset(addr);
for (int i = 0; i < 32; i++) {
new_value = extract32(value, i, 1);
if (extract32(prev_value, i, 1) && !new_value) {
@@ -82,11 +104,12 @@ static void stm32_rcc_write(void *opaque, hwaddr addr,
}
}
return;
case STM32_RCC_AHB1_ENR...STM32_RCC_APB2_ENR:
case STM32_RCC_AHB1_ENR ... STM32_RCC_AHB3_ENR:
case STM32_RCC_APB1_ENR ... STM32_RCC_APB2_ENR:
prev_value = s->regs[addr / 4];
s->regs[addr / 4] = value;
irq_offset = ((addr - STM32_RCC_AHB1_ENR) / 4) * 32;
irq_offset = reg_offset_to_irq_offset(addr);
for (int i = 0; i < 32; i++) {
new_value = extract32(value, i, 1);
if (!extract32(prev_value, i, 1) && new_value) {
+16 -1
View File
@@ -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. */
+21 -6
View File
@@ -176,16 +176,31 @@ static void tx_padding_and_crc(eTSEC *etsec, uint32_t min_frame_len)
static void process_tx_fcb(eTSEC *etsec)
{
uint8_t flags = (uint8_t)(*etsec->tx_buffer);
/* L3 header offset from start of frame */
/* L3 header offset from start of frame (FCB byte 3) */
uint8_t l3_header_offset = (uint8_t)*(etsec->tx_buffer + 3);
/* L4 header offset from start of L3 header */
/* L4 header offset from start of L3 header (FCB byte 2) */
uint8_t l4_header_offset = (uint8_t)*(etsec->tx_buffer + 2);
/* L3 header */
uint8_t *l3_header = etsec->tx_buffer + 8 + l3_header_offset;
/* L4 header */
uint8_t *l4_header = l3_header + l4_header_offset;
uint8_t *l3_header;
uint8_t *l4_header;
int csum = 0;
/*
* Validate FCB header offsets before pointer arithmetic. The highest
* byte accessed is l4_header[7], at offset
* 8 (FCB size) + l3_header_offset + l4_header_offset + 7
* from tx_buffer. Drop the frame if this exceeds the buffer length.
*/
if (etsec->tx_buffer_len < 8u + l3_header_offset + l4_header_offset + 8u) {
qemu_log_mask(LOG_GUEST_ERROR,
"eTSEC: FCB offsets exceed frame length, dropping\n");
return;
}
/* L3 header */
l3_header = etsec->tx_buffer + 8 + l3_header_offset;
/* L4 header */
l4_header = l3_header + l4_header_offset;
/* if packet is IP4 and IP checksum is requested */
if (flags & FCB_TX_IP && flags & FCB_TX_CIP) {
csum |= CSUM_IP;
+3 -4
View File
@@ -93,9 +93,6 @@ void net_tx_pkt_update_ip_hdr_checksum(struct NetTxPkt *pkt)
uint16_t csum;
assert(pkt);
pkt->l3_hdr.ip.ip_len = cpu_to_be16(pkt->payload_len +
pkt->vec[NET_TX_PKT_L3HDR_FRAG].iov_len);
pkt->l3_hdr.ip.ip_sum = 0;
csum = net_raw_checksum(pkt->l3_hdr.octets,
pkt->vec[NET_TX_PKT_L3HDR_FRAG].iov_len);
@@ -117,7 +114,9 @@ void net_tx_pkt_update_ip_checksums(struct NetTxPkt *pkt)
if (gso_type == VIRTIO_NET_HDR_GSO_TCPV4 ||
gso_type == VIRTIO_NET_HDR_GSO_UDP) {
/* Calculate IP header checksum */
/* Set ip_len and calculate IP header checksum */
pkt->l3_hdr.ip.ip_len = cpu_to_be16(pkt->payload_len +
pkt->vec[NET_TX_PKT_L3HDR_FRAG].iov_len);
net_tx_pkt_update_ip_hdr_checksum(pkt);
/* Calculate IP pseudo header checksum */
+14 -7
View File
@@ -1374,6 +1374,11 @@ static void virtio_net_unload_ebpf(VirtIONet *n)
ebpf_rss_unload(&n->ebpf_rss);
}
static bool virtio_net_rss_indirections_len_valid(uint16_t len)
{
return is_power_of_2(len) && len <= VIRTIO_NET_RSS_MAX_TABLE_LEN;
}
static uint16_t virtio_net_handle_rss(VirtIONet *n,
struct iovec *iov,
unsigned int iov_cnt,
@@ -1411,14 +1416,9 @@ static uint16_t virtio_net_handle_rss(VirtIONet *n,
if (!do_rss) {
n->rss_data.indirections_len = 0;
}
if (n->rss_data.indirections_len >= VIRTIO_NET_RSS_MAX_TABLE_LEN) {
err_msg = "Too large indirection table";
err_value = n->rss_data.indirections_len;
goto error;
}
n->rss_data.indirections_len++;
if (!is_power_of_2(n->rss_data.indirections_len)) {
err_msg = "Invalid size of indirection table";
if (!virtio_net_rss_indirections_len_valid(n->rss_data.indirections_len)) {
err_msg = "Invalid indirection table length";
err_value = n->rss_data.indirections_len;
goto error;
}
@@ -3427,6 +3427,13 @@ static int virtio_net_rss_post_load(void *opaque, int version_id)
n->rss_data.supported_hash_types = VIRTIO_NET_RSS_SUPPORTED_HASHES;
}
if (!virtio_net_rss_indirections_len_valid(n->rss_data.indirections_len)) {
error_report("virtio-net: saved image has invalid RSS "
"indirections_len: %u",
n->rss_data.indirections_len);
return -EINVAL;
}
return 0;
}
+1 -1
View File
@@ -1079,7 +1079,7 @@ vmxnet3_io_bar0_write(void *opaque, hwaddr addr,
int tx_queue_idx =
VMW_MULTIREG_IDX_BY_ADDR(addr, VMXNET3_REG_TXPROD,
VMXNET3_REG_ALIGN);
if (tx_queue_idx <= s->txq_num) {
if (tx_queue_idx < s->txq_num) {
vmxnet3_process_tx_queue(s, tx_queue_idx);
} else {
qemu_log_mask(LOG_GUEST_ERROR, "vmxnet3: Illegal TX queue %d/%d\n",
+3
View File
@@ -103,6 +103,9 @@ static unsigned int tdk_read(struct PHY *phy, unsigned int req)
case 17:
/* Marvell PHY on many xilinx boards. */
r = 0x8000; /* 1000Mb */
if (phy->link) {
r |= 0x0400; /* Link is up */
}
break;
case 18:
{
+29 -6
View File
@@ -1088,6 +1088,8 @@ static uint16_t nvme_map_sgl(NvmeCtrl *n, NvmeSg *sg, NvmeSglDescriptor sgl,
}
for (;;) {
size_t prev_len = len;
switch (NVME_SGL_TYPE(sgld->type)) {
case NVME_SGL_DESCR_TYPE_SEGMENT:
case NVME_SGL_DESCR_TYPE_LAST_SEGMENT:
@@ -1168,6 +1170,17 @@ static uint16_t nvme_map_sgl(NvmeCtrl *n, NvmeSg *sg, NvmeSglDescriptor sgl,
if (status) {
goto unmap;
}
/*
* Reject if this segment made no forward progress. The host should
* have skipped linking an empty segment. While not strictly spec
* compliant, allowing this makes it easy for a pathological host to
* create an infinite loop.
*/
if (len == prev_len) {
status = NVME_INVALID_SGL_SEG_DESCR | NVME_DNR;
goto unmap;
}
}
out:
@@ -6242,10 +6255,6 @@ static uint16_t nvme_get_feature_fdp_events(NvmeCtrl *n, NvmeNamespace *ns,
for (uint8_t event_type = 0; event_type < FDP_EVT_MAX; event_type++) {
uint8_t shift = nvme_fdp_evf_shifts[event_type];
if (!shift && event_type) {
/*
* only first entry (event_type == 0) has a shift value of 0
* other entries are simply unpopulated.
*/
continue;
}
@@ -6490,9 +6499,9 @@ static uint16_t nvme_set_feature_fdp_events(NvmeCtrl *n, NvmeNamespace *ns,
uint8_t noet = (cdw11 >> 16) & 0xff;
uint16_t ret, ruhid;
uint8_t enable = le32_to_cpu(cmd->cdw12) & 0x1;
uint8_t event_mask = 0;
uint64_t event_mask = 0;
unsigned int i;
g_autofree uint8_t *events = g_malloc0(noet);
g_autofree uint8_t *events = NULL;
NvmeRuHandle *ruh = NULL;
assert(ns);
@@ -6505,15 +6514,29 @@ static uint16_t nvme_set_feature_fdp_events(NvmeCtrl *n, NvmeNamespace *ns,
return NVME_INVALID_FIELD | NVME_DNR;
}
if (unlikely(noet == 0)) {
return NVME_SUCCESS;
}
ruhid = ns->fdp.phs[ph];
ruh = &n->subsys->endgrp.fdp.ruhs[ruhid];
events = g_malloc0(noet);
ret = nvme_h2c(n, events, noet, req);
if (ret) {
return ret;
}
for (i = 0; i < noet; i++) {
/*
* We ignore requests to enable tracking of unsupported FDP event types
*/
uint8_t event_type = events[i];
uint8_t shift = nvme_fdp_evf_shifts[event_type];
if (!shift && event_type) {
continue;
}
event_mask |= (1 << nvme_fdp_evf_shifts[events[i]]);
}
+8 -1
View File
@@ -160,7 +160,14 @@ typedef struct NvmeZone {
#define NVME_FDP_MAX_NS_RUHS 32u
#define FDPVSS 0
static const uint8_t nvme_fdp_evf_shifts[FDP_EVT_MAX] = {
/*
* NOTE: Apart from event type 0, any event type with a shift value of 0 is
* considered unsupported and thus skipped in get/set features calls.
*
* NOTE: NvmeRuHandle uses a 64bit event mask - refactor to support event types
* of 63 or greater.
*/
static const uint8_t nvme_fdp_evf_shifts[FDP_EVT_MAX + 1] = {
/* Host events */
[FDP_EVT_RU_NOT_FULLY_WRITTEN] = 0,
[FDP_EVT_RU_ATL_EXCEEDED] = 1,
+23 -4
View File
@@ -78,14 +78,21 @@ static bool pcie_doe_discovery(DOECap *doe_cap)
return true;
}
static void pcie_doe_reset_write_mbox(DOECap *st)
{
st->write_mbox_len = 0;
memset(st->write_mbox, 0, PCI_DOE_DW_SIZE_MAX * DWORD_BYTE);
}
static void pcie_doe_reset_mbox(DOECap *st)
{
st->read_mbox_idx = 0;
st->read_mbox_len = 0;
st->write_mbox_len = 0;
memset(st->read_mbox, 0, PCI_DOE_DW_SIZE_MAX * DWORD_BYTE);
memset(st->write_mbox, 0, PCI_DOE_DW_SIZE_MAX * DWORD_BYTE);
pcie_doe_reset_write_mbox(st);
}
void pcie_doe_init(PCIDevice *dev, DOECap *doe_cap, uint16_t offset,
@@ -356,8 +363,20 @@ void pcie_doe_write_config(DOECap *doe_cap,
if (size != DWORD_BYTE) {
return;
}
doe_cap->write_mbox[doe_cap->write_mbox_len] = val;
doe_cap->write_mbox_len++;
if (doe_cap->write_mbox_len < PCI_DOE_DW_SIZE_MAX) {
doe_cap->write_mbox[doe_cap->write_mbox_len] = val;
doe_cap->write_mbox_len++;
} else {
qemu_log_mask(LOG_GUEST_ERROR,
"Mailbox write length (%d) overflow\n",
doe_cap->write_mbox_len);
/*
* Too much data has been written, it can't
* "match the Length indicated in DOE Data Object Header 2"
* so we drop the entire object.
*/
pcie_doe_reset_write_mbox(doe_cap);
}
break;
case PCI_EXP_DOE_CAP:
/* fallthrough */
+1
View File
@@ -86,6 +86,7 @@ struct riscv_iommu_pq_record {
#define RISCV_IOMMU_CAP_SV57X4 BIT_ULL(19)
#define RISCV_IOMMU_CAP_MSI_FLAT BIT_ULL(22)
#define RISCV_IOMMU_CAP_MSI_MRIF BIT_ULL(23)
#define RISCV_IOMMU_CAP_AMO_HWAD BIT_ULL(24)
#define RISCV_IOMMU_CAP_ATS BIT_ULL(25)
#define RISCV_IOMMU_CAP_T2GPA BIT_ULL(26)
#define RISCV_IOMMU_CAP_IGS GENMASK_ULL(29, 28)
+15 -1
View File
@@ -26,6 +26,7 @@
#include "qemu/host-utils.h"
#include "qemu/module.h"
#include "qom/object.h"
#include "target/riscv/cpu_bits.h"
#include "trace.h"
#include "riscv-iommu.h"
@@ -143,7 +144,20 @@ static void riscv_iommu_sysdev_send_MSI(RISCVIOMMUStateSys *s,
address_space_stl_le(&address_space_memory, msi_addr,
msi_data, MEMTXATTRS_UNSPECIFIED, &result);
trace_riscv_iommu_sys_msi_sent(vector, msi_addr, msi_data, result);
if (result == MEMTX_OK) {
trace_riscv_iommu_sys_msi_sent(vector, msi_addr, msi_data, result);
} else {
/* Record an access fault error in the fault queue */
struct riscv_iommu_fq_record ev = { 0 };
RISCVIOMMUState *iommu = &s->iommu;
ev.hdr = set_field(ev.hdr, RISCV_IOMMU_FQ_HDR_CAUSE,
RISCV_IOMMU_FQ_CAUSE_MSI_WR_FAULT);
ev.hdr = set_field(ev.hdr, RISCV_IOMMU_FQ_HDR_TTYPE,
RISCV_IOMMU_FQ_TTYPE_UADDR_WR);
riscv_iommu_fault(iommu, &ev);
}
}
static void riscv_iommu_sysdev_notify(RISCVIOMMUState *iommu,
+131 -26
View File
@@ -49,7 +49,8 @@ struct RISCVIOMMUSpace {
IOMMUMemoryRegion iova_mr; /* IOVA memory region for attached device */
AddressSpace iova_as; /* IOVA address space for attached device */
RISCVIOMMUState *iommu; /* Managing IOMMU device state */
uint32_t devid; /* Requester identifier, AKA device_id */
PCIBus *bus; /* PCI bus of the requester */
uint8_t devfn; /* Requester identifier, AKA device_id */
bool notifier; /* IOMMU unmap notifier enabled */
QLIST_ENTRY(RISCVIOMMUSpace) list;
};
@@ -74,6 +75,15 @@ struct RISCVIOMMUEntry {
/* IOMMU index for transactions without process_id specified. */
#define RISCV_IOMMU_NOPROCID 0
static uint32_t riscv_iommu_space_devid(RISCVIOMMUSpace *as)
{
uint32_t devid = PCI_BUILD_BDF(pci_bus_num(as->bus), as->devfn);
/* FIXME: PCIe bus remapping for attached endpoints. */
devid |= as->iommu->bus << 8;
return devid;
}
static uint8_t riscv_iommu_get_icvec_vector(uint32_t icvec, uint32_t vec_type)
{
switch (vec_type) {
@@ -108,8 +118,7 @@ void riscv_iommu_notify(RISCVIOMMUState *s, int vec_type)
}
}
static void riscv_iommu_fault(RISCVIOMMUState *s,
struct riscv_iommu_fq_record *ev)
void riscv_iommu_fault(RISCVIOMMUState *s, struct riscv_iommu_fq_record *ev)
{
uint32_t ctrl = riscv_iommu_reg_get32(s, RISCV_IOMMU_REG_FQCSR);
uint32_t head = riscv_iommu_reg_get32(s, RISCV_IOMMU_REG_FQH) & s->fq_mask;
@@ -272,6 +281,7 @@ static hwaddr riscv_iommu_napot_page_mask(hwaddr ppn, hwaddr addr, hwaddr *out)
static int riscv_iommu_spa_fetch(RISCVIOMMUState *s, RISCVIOMMUContext *ctx,
IOMMUTLBEntry *iotlb)
{
IOMMUAccessFlags pte_perm;
dma_addr_t addr, base;
uint64_t satp, gatp, pte;
bool en_s, en_g;
@@ -287,6 +297,7 @@ static int riscv_iommu_spa_fetch(RISCVIOMMUState *s, RISCVIOMMUContext *ctx,
G_STAGE = 1,
} pass;
MemTxResult ret;
bool pv = !!ctx->process_id;
satp = get_field(ctx->satp, RISCV_IOMMU_ATP_MODE_FIELD);
gatp = get_field(ctx->gatp, RISCV_IOMMU_ATP_MODE_FIELD);
@@ -406,6 +417,11 @@ static int riscv_iommu_spa_fetch(RISCVIOMMUState *s, RISCVIOMMUContext *ctx,
const bool ade =
ctx->tc & (pass ? RISCV_IOMMU_DC_TC_GADE : RISCV_IOMMU_DC_TC_SADE);
if (ade && !(s->cap & RISCV_IOMMU_CAP_AMO_HWAD)) {
/* GADE/SADE are reserved bits if AMO_HWAD is cleared. */
return RISCV_IOMMU_FQ_CAUSE_DDT_MISCONFIGURED;
}
/* Address range check before first level lookup */
if (!sc[pass].step) {
const uint64_t va_len = va_skip + va_bits;
@@ -458,6 +474,15 @@ static int riscv_iommu_spa_fetch(RISCVIOMMUState *s, RISCVIOMMUContext *ctx,
if (!(pte & PTE_V)) {
break; /* Invalid PTE */
} else if (pte & PTE_RESERVED(false)) {
break; /* Reserved PTE bits set */
} else if (!(pte & PTE_U) && !pv) {
/*
* All accesses are assumed to be User mode unless
* process_id is valid (pv). In case we have a
* non-user mode PTE and !pv we need to fault.
*/
break;
} else if (!(pte & (PTE_R | PTE_W | PTE_X))) {
base = PPN_PHYS(ppn); /* Inner PTE, continue walking */
} else if ((pte & (PTE_R | PTE_W | PTE_X)) == PTE_W) {
@@ -470,10 +495,20 @@ static int riscv_iommu_spa_fetch(RISCVIOMMUState *s, RISCVIOMMUContext *ctx,
break; /* Read access check failed */
} else if ((iotlb->perm & IOMMU_WO) && !(pte & PTE_W)) {
break; /* Write access check failed */
} else if ((iotlb->perm & IOMMU_RO) && !ade && !(pte & PTE_A)) {
} else if (!ade && !(pte & PTE_A)) {
break; /* Access bit not set */
} else if ((iotlb->perm & IOMMU_WO) && !ade && !(pte & PTE_D)) {
break; /* Dirty bit not set */
} else if (pass == G_STAGE && !(pte & PTE_U)) {
/*
* riscv-iommu spec 1.0: "When checking the U bit in a
* second-stage PTE, the transaction is treated as
* not requesting supervisor privilege."
*
* I.e. we need to fault if this is a non-user PTE since
* we are always in user mode at this point.
*/
break;
} else {
/* Leaf PTE, translation completed. */
sc[pass].step = sc[pass].levels;
@@ -499,8 +534,16 @@ static int riscv_iommu_spa_fetch(RISCVIOMMUState *s, RISCVIOMMUContext *ctx,
}
/* Translation phase completed (GPA or SPA) */
iotlb->translated_addr = base;
iotlb->perm = (pte & PTE_W) ? ((pte & PTE_R) ? IOMMU_RW : IOMMU_WO)
: IOMMU_RO;
/*
* Do a bit_and between the PTE bits and the original
* request flags to determine the exact permission we
* need, i.e. if the original request is RO and the
* PTE has RW flags the actual perm is RO.
*/
pte_perm = (pte & PTE_W) ? ((pte & PTE_R) ? IOMMU_RW : IOMMU_WO)
: IOMMU_RO;
iotlb->perm &= pte_perm;
/* Check MSI GPA address match */
if (pass == S_STAGE && (iotlb->perm & IOMMU_WO) &&
@@ -536,6 +579,14 @@ static int riscv_iommu_spa_fetch(RISCVIOMMUState *s, RISCVIOMMUContext *ctx,
}
} while (1);
/*
* riscv_iommu_translate() will receive a fault and then call
* riscv_iommu_report_fault() using iotlb->translated_addr
* as iotval2. Update translated_addr it with the latest
* translated addr we have.
*/
iotlb->translated_addr = addr;
return (iotlb->perm & IOMMU_WO) ?
(pass ? RISCV_IOMMU_FQ_CAUSE_WR_FAULT_VS :
RISCV_IOMMU_FQ_CAUSE_WR_FAULT_S) :
@@ -638,6 +689,27 @@ static MemTxResult riscv_iommu_msi_write(RISCVIOMMUState *s,
switch (get_field(pte[0], RISCV_IOMMU_MSI_PTE_M)) {
case RISCV_IOMMU_MSI_PTE_M_BASIC:
/*
* riscv-iommu spec MSI PTE basic translate mode:
* "When an MSI PTE has fields V = 1, C = 0, and M = 3
* (basic translate mode), the PTE's complete format is:
* First doubleword: bit 63 C, = 0
* bits 53:10 PPN
* bits 2:1 M, = 3
* bit 0 V, = 1
* All other bits of the first doubleword are reserved
* and must be set to zeros by software. The second
* doubleword is ignored by an IOMMU so is free for
* software to use."
*
* In other words, bits 62:54 and 9:3 of pte[0] are reserved.
*/
if (pte[0] & (GENMASK_ULL(62, 54) | GENMASK_ULL(9, 3))) {
res = MEMTX_DECODE_ERROR;
cause = RISCV_IOMMU_FQ_CAUSE_MSI_MISCONFIGURED;
goto err;
}
/* MSI Pass-through mode */
addr = PPN_PHYS(get_field(pte[0], RISCV_IOMMU_MSI_PTE_PPN));
@@ -780,6 +852,21 @@ static bool riscv_iommu_validate_device_ctx(RISCVIOMMUState *s,
return false;
}
if (gatp != RISCV_IOMMU_DC_IOHGATP_MODE_BARE) {
uint64_t iohgatp_ppn = get_field(ctx->gatp,
RISCV_IOMMU_DC_IOHGATP_PPN);
/*
* One of the conditions for a misconfigured DDT entry
* according to the riscv-spec: "DC.iohgatp.MODE is not
* Bare and the root page table (address) determined by
* DC.iohgatp.PPN is not aligned to a 16-KiB boundary."
*/
if (PPN_PHYS(iohgatp_ppn) & ((1ULL << 14) - 1)) {
return false;
}
}
fsc_mode = get_field(ctx->satp, RISCV_IOMMU_DC_FSC_MODE);
if (ctx->tc & RISCV_IOMMU_DC_TC_PDTV) {
@@ -1320,6 +1407,7 @@ static void riscv_iommu_ctx_inval(RISCVIOMMUState *s, GHFunc func,
/* Find or allocate translation context for a given {device_id, process_id} */
static RISCVIOMMUContext *riscv_iommu_ctx(RISCVIOMMUState *s,
unsigned devid, unsigned process_id,
IOMMUAccessFlags perm, uint64_t iova,
void **ref)
{
GHashTable *ctx_cache;
@@ -1329,6 +1417,7 @@ static RISCVIOMMUContext *riscv_iommu_ctx(RISCVIOMMUState *s,
.process_id = process_id,
};
unsigned mode = get_field(s->ddtp, RISCV_IOMMU_DDTP_MODE);
uint32_t fault_type;
ctx_cache = g_hash_table_ref(s->ctx_cache);
@@ -1364,8 +1453,21 @@ static RISCVIOMMUContext *riscv_iommu_ctx(RISCVIOMMUState *s,
g_hash_table_unref(ctx_cache);
*ref = NULL;
riscv_iommu_report_fault(s, ctx, RISCV_IOMMU_FQ_TTYPE_UADDR_RD,
fault, !!process_id, 0, 0);
/*
* TODO: (1) do we need to distinguish other fault types
* for ctx fetching and (2) evaluate putting the 'fault_type'
* logic inside riscv_iommu_report_fault() - there's at
* least one other place (end of riscv_iommu_translate())
* that does something similar.
*/
if (perm & IOMMU_RO) {
fault_type = RISCV_IOMMU_FQ_TTYPE_UADDR_RD;
} else {
fault_type = RISCV_IOMMU_FQ_TTYPE_UADDR_WR;
}
riscv_iommu_report_fault(s, ctx, fault_type, fault,
!!process_id, iova, 0);
g_free(ctx);
return NULL;
@@ -1379,15 +1481,13 @@ static void riscv_iommu_ctx_put(RISCVIOMMUState *s, void *ref)
}
/* Find or allocate address space for a given device */
static AddressSpace *riscv_iommu_space(RISCVIOMMUState *s, uint32_t devid)
static AddressSpace *riscv_iommu_space(RISCVIOMMUState *s, PCIBus *bus,
int devfn)
{
RISCVIOMMUSpace *as;
/* FIXME: PCIe bus remapping for attached endpoints. */
devid |= s->bus << 8;
QLIST_FOREACH(as, &s->spaces, list) {
if (as->devid == devid) {
if (as->bus == bus && as->devfn == devfn) {
break;
}
}
@@ -1397,10 +1497,11 @@ static AddressSpace *riscv_iommu_space(RISCVIOMMUState *s, uint32_t devid)
as = g_new0(RISCVIOMMUSpace, 1);
as->iommu = s;
as->devid = devid;
as->bus = bus;
as->devfn = devfn;
snprintf(name, sizeof(name), "riscv-iommu-%04x:%02x.%d-iova",
PCI_BUS_NUM(as->devid), PCI_SLOT(as->devid), PCI_FUNC(as->devid));
pci_bus_num(bus), PCI_SLOT(devfn), PCI_FUNC(devfn));
/* IOVA address space, untranslated addresses */
memory_region_init_iommu(&as->iova_mr, sizeof(as->iova_mr),
@@ -1410,8 +1511,8 @@ static AddressSpace *riscv_iommu_space(RISCVIOMMUState *s, uint32_t devid)
QLIST_INSERT_HEAD(&s->spaces, as, list);
trace_riscv_iommu_new(s->parent_obj.id, PCI_BUS_NUM(as->devid),
PCI_SLOT(as->devid), PCI_FUNC(as->devid));
trace_riscv_iommu_new(s->parent_obj.id, pci_bus_num(bus),
PCI_SLOT(devfn), PCI_FUNC(devfn));
}
return &as->iova_as;
}
@@ -1682,7 +1783,8 @@ done:
if (fault) {
unsigned ttype = RISCV_IOMMU_FQ_TTYPE_PCIE_ATS_REQ;
if (iotlb->perm & IOMMU_RW) {
if ((iotlb->perm & IOMMU_RW) == IOMMU_RW
|| iotlb->perm & IOMMU_WO) {
ttype = RISCV_IOMMU_FQ_TTYPE_UADDR_WR;
} else if (iotlb->perm & IOMMU_RO) {
ttype = RISCV_IOMMU_FQ_TTYPE_UADDR_RD;
@@ -1735,7 +1837,7 @@ static void riscv_iommu_ats(RISCVIOMMUState *s,
pid = get_field(cmd->dword0, RISCV_IOMMU_CMD_ATS_PID);
QLIST_FOREACH(as, &s->spaces, list) {
if (as->devid == devid) {
if (riscv_iommu_space_devid(as) == devid) {
break;
}
}
@@ -2096,6 +2198,8 @@ static void riscv_iommu_process_dbg(RISCVIOMMUState *s)
uint64_t ctrl = riscv_iommu_reg_get64(s, RISCV_IOMMU_REG_TR_REQ_CTL);
unsigned devid = get_field(ctrl, RISCV_IOMMU_TR_REQ_CTL_DID);
unsigned pid = get_field(ctrl, RISCV_IOMMU_TR_REQ_CTL_PID);
IOMMUAccessFlags perm = ctrl & RISCV_IOMMU_TR_REQ_CTL_NW
? IOMMU_RO : IOMMU_RW;
RISCVIOMMUContext *ctx;
void *ref;
@@ -2103,7 +2207,7 @@ static void riscv_iommu_process_dbg(RISCVIOMMUState *s)
return;
}
ctx = riscv_iommu_ctx(s, devid, pid, &ref);
ctx = riscv_iommu_ctx(s, devid, pid, perm, iova, &ref);
if (ctx == NULL) {
riscv_iommu_reg_set64(s, RISCV_IOMMU_REG_TR_RESPONSE,
RISCV_IOMMU_TR_RESPONSE_FAULT |
@@ -2111,7 +2215,7 @@ static void riscv_iommu_process_dbg(RISCVIOMMUState *s)
} else {
IOMMUTLBEntry iotlb = {
.iova = iova,
.perm = ctrl & RISCV_IOMMU_TR_REQ_CTL_NW ? IOMMU_RO : IOMMU_RW,
.perm = perm,
.addr_mask = ~0,
.target_as = NULL,
};
@@ -2446,7 +2550,7 @@ static MemTxResult riscv_iommu_trap_write(void *opaque, hwaddr addr,
/* FIXME: PCIe bus remapping for attached endpoints. */
devid |= s->bus << 8;
ctx = riscv_iommu_ctx(s, devid, 0, &ref);
ctx = riscv_iommu_ctx(s, devid, 0, IOMMU_RW, addr, &ref);
if (ctx == NULL) {
res = MEMTX_ACCESS_ERROR;
} else {
@@ -2745,8 +2849,9 @@ static IOMMUTLBEntry riscv_iommu_memory_region_translate(
.addr_mask = ~0ULL,
.perm = flag,
};
uint32_t devid = riscv_iommu_space_devid(as);
ctx = riscv_iommu_ctx(as->iommu, as->devid, iommu_idx, &ref);
ctx = riscv_iommu_ctx(as->iommu, devid, iommu_idx, flag, addr, &ref);
if (ctx == NULL) {
/* Translation disabled or invalid. */
iotlb.addr_mask = 0;
@@ -2758,8 +2863,8 @@ static IOMMUTLBEntry riscv_iommu_memory_region_translate(
}
/* Trace all dma translations with original access flags. */
trace_riscv_iommu_dma(as->iommu->parent_obj.id, PCI_BUS_NUM(as->devid),
PCI_SLOT(as->devid), PCI_FUNC(as->devid), iommu_idx,
trace_riscv_iommu_dma(as->iommu->parent_obj.id, PCI_BUS_NUM(devid),
PCI_SLOT(devid), PCI_FUNC(devid), iommu_idx,
IOMMU_FLAG_STR[flag & IOMMU_RW], iotlb.iova,
iotlb.translated_addr);
@@ -2807,7 +2912,7 @@ static AddressSpace *riscv_iommu_find_as(PCIBus *bus, void *opaque, int devfn)
/* Find first matching IOMMU */
while (s != NULL && as == NULL) {
as = riscv_iommu_space(s, PCI_BUILD_BDF(pci_bus_num(bus), devfn));
as = riscv_iommu_space(s, bus, devfn);
s = s->iommus.le_next;
}
+1
View File
@@ -99,6 +99,7 @@ void riscv_iommu_pci_setup_iommu(RISCVIOMMUState *iommu, PCIBus *bus,
void riscv_iommu_set_cap_igs(RISCVIOMMUState *s, riscv_iommu_igs_mode mode);
void riscv_iommu_reset(RISCVIOMMUState *s);
void riscv_iommu_notify(RISCVIOMMUState *s, int vec_type);
void riscv_iommu_fault(RISCVIOMMUState *s, struct riscv_iommu_fq_record *ev);
typedef struct RISCVIOMMUContext RISCVIOMMUContext;
/* Device translation context state. */
+2
View File
@@ -100,6 +100,8 @@ static void riscv_acpi_madt_add_rintc(uint32_t uid,
build_append_int_noprefix(entry,
ACPI_BUILD_INTC_ID(
arch_ids->cpus[uid].props.node_id,
kvm_enabled() ?
local_cpu_id :
2 * local_cpu_id + 1),
4);
} else {
+24
View File
@@ -1076,6 +1076,12 @@ static int css_interpret_ccw(SubchDev *sch, hwaddr ccw_addr,
ret = -EINVAL;
break;
}
/* Limit the number of TICs in a given channel program */
if (sch->ccw_tic_cnt == 255) {
ret = -EINVAL;
break;
}
sch->ccw_tic_cnt++;
sch->channel_prog = ccw.cda;
ret = -EAGAIN;
break;
@@ -1127,6 +1133,7 @@ static void sch_handle_start_func_virtual(SubchDev *sch)
sch->ccw_fmt_1 = !!(orb->ctrl0 & ORB_CTRL0_MASK_FMT);
schib->scsw.flags |= (sch->ccw_fmt_1) ? SCSW_FLAGS_MASK_FMT : 0;
sch->ccw_no_data_cnt = 0;
sch->ccw_tic_cnt = 0;
suspend_allowed = !!(orb->ctrl0 & ORB_CTRL0_MASK_SPND);
} else {
/* Start Function resumed via rsch */
@@ -1870,6 +1877,7 @@ int css_collect_chp_desc(int m, uint8_t cssid, uint8_t f_chpid, uint8_t l_chpid,
int i, desc_size;
uint32_t words[8];
uint32_t chpid_type_word;
uint32_t max_chpids, chpid_count = 0;
CssImage *css;
if (!m && !cssid) {
@@ -1880,9 +1888,25 @@ int css_collect_chp_desc(int m, uint8_t cssid, uint8_t f_chpid, uint8_t l_chpid,
if (!css) {
return 0;
}
if (rfmt == 0) {
max_chpids = 256;
} else if (rfmt == 1) {
max_chpids = 127;
} else {
/* Should be rejected by caller */
return 0;
}
desc_size = 0;
for (i = f_chpid; i <= l_chpid; i++) {
if (css->chpids[i].in_use) {
/* Limit number of CHPIDs sent back */
if (chpid_count == max_chpids) {
break;
}
chpid_count++;
chpid_type_word = 0x80000000 | (css->chpids[i].type << 8) | i;
if (rfmt == 0) {
words[0] = cpu_to_be32(chpid_type_word);
+6
View File
@@ -286,6 +286,7 @@ static void read_event_data(SCLPEventFacility *ef, SCCB *sccb)
static void write_event_mask(SCLPEventFacility *ef, SCCB *sccb)
{
WriteEventMask *we_mask = (WriteEventMask *) sccb;
uint16_t sccb_length = be16_to_cpu(sccb->h.length);
uint16_t mask_length = be16_to_cpu(we_mask->mask_length);
sccb_mask_t tmp_mask;
@@ -294,6 +295,11 @@ static void write_event_mask(SCLPEventFacility *ef, SCCB *sccb)
return;
}
if (sccb_length < sizeof(WriteEventMask) + 4 * mask_length) {
sccb->h.response_code = cpu_to_be16(SCLP_RC_INSUFFICIENT_SCCB_LENGTH);
return;
}
/*
* Note: We currently only support masks up to 8 byte length;
* the remainder is filled up with zeroes. Older Linux
+30 -2
View File
@@ -392,13 +392,22 @@ static int zpci_endian_swap(uint64_t *ptr, uint8_t len)
static MemoryRegion *s390_get_subregion(MemoryRegion *mr, uint64_t offset,
uint8_t len)
{
uint64_t last = offset + len;
MemoryRegion *subregion;
uint64_t subregion_size;
/*
* Ensure the region is valid, the calculated address cannot wrap and that
* it falls within this region.
*/
if (!mr || offset > last || last > memory_region_size(mr)) {
return NULL;
}
QTAILQ_FOREACH(subregion, &mr->subregions, subregions_link) {
subregion_size = memory_region_size(subregion);
if ((offset >= subregion->addr) &&
(offset + len) <= (subregion->addr + subregion_size)) {
(last) <= (subregion->addr + subregion_size)) {
mr = subregion;
break;
}
@@ -413,6 +422,10 @@ static MemTxResult zpci_read_bar(S390PCIBusDevice *pbdev, uint8_t pcias,
mr = pbdev->pdev->io_regions[pcias].memory;
mr = s390_get_subregion(mr, offset, len);
if (!mr) {
return MEMTX_ERROR;
}
offset -= mr->addr;
return memory_region_dispatch_read(mr, offset, data,
size_memop(len) | MO_BE,
@@ -513,6 +526,10 @@ static MemTxResult zpci_write_bar(S390PCIBusDevice *pbdev, uint8_t pcias,
mr = pbdev->pdev->io_regions[pcias].memory;
mr = s390_get_subregion(mr, offset, len);
if (!mr) {
return MEMTX_ERROR;
}
offset -= mr->addr;
return memory_region_dispatch_write(mr, offset, data,
size_memop(len) | MO_BE,
@@ -753,10 +770,16 @@ int rpcit_service_call(S390CPU *cpu, uint8_t r1, uint8_t r2, uintptr_t ra)
goto err;
}
if (end < iommu->pba || start > iommu->pal) {
if (end < start || end < iommu->pba || start > iommu->pal) {
error = ERR_EVENT_OORANGE;
goto err;
}
/*
* If the specified range at least partially overlaps the registered
* aperture, clamp the request to the aperture and ignore the rest.
*/
sstart = MAX(start, iommu->pba);
end = MIN(end, iommu->pal + 1);
retry:
start = sstart;
@@ -900,6 +923,11 @@ int pcistb_service_call(S390CPU *cpu, uint8_t r1, uint8_t r3, uint64_t gaddr,
mr = pbdev->pdev->io_regions[pcias].memory;
mr = s390_get_subregion(mr, offset, len);
if (!mr) {
s390_program_interrupt(env, PGM_OPERAND, ra);
return 0;
}
offset -= mr->addr;
for (i = 0; i < len; i += 8) {
+3 -1
View File
@@ -327,7 +327,8 @@ int sclp_service_call(S390CPU *cpu, uint64_t sccb, uint32_t code)
/*
* we want to work on a private copy of the sccb, to prevent guests
* from playing dirty tricks by modifying the memory content after
* the host has checked the values
* the host has checked the values.
* Reuse the previously fetched header
*/
work_sccb = g_malloc0(be16_to_cpu(header.length));
ret = address_space_read(as, sccb, attrs,
@@ -335,6 +336,7 @@ int sclp_service_call(S390CPU *cpu, uint64_t sccb, uint32_t code)
if (ret != MEMTX_OK) {
return -PGM_ADDRESSING;
}
work_sccb->h = header;
if (!sclp_command_code_valid(code)) {
work_sccb->h.response_code = cpu_to_be16(SCLP_RC_INVALID_SCLP_COMMAND);
+5
View File
@@ -97,6 +97,11 @@ static int write_event_data(SCLPEvent *event, EventBufferHeader *evt_buf_hdr)
ebh);
SCLPEventCPI *e = SCLP_EVENT_CPI(event);
/* Caller checks sccb length, buffer header checking is our duty */
if (be16_to_cpu(evt_buf_hdr->length) != sizeof(ControlProgramIdMsg)) {
return SCLP_RC_INCONSISTENT_LENGTHS;
}
ascii_put(e->system_type, (char *)cpim->data.system_type,
sizeof(cpim->data.system_type));
ascii_put(e->system_name, (char *)cpim->data.system_name,
+4
View File
@@ -811,6 +811,10 @@ static void mptsas_soft_reset(MPTSASState *s)
s->intr_status = 0;
s->intr_mask = save_mask;
s->doorbell_state = DOORBELL_NONE;
s->doorbell_reply_idx = 0;
s->doorbell_reply_size = 0;
s->reply_free_tail = 0;
s->reply_free_head = 0;
s->reply_post_tail = 0;
+22 -2
View File
@@ -439,7 +439,7 @@ static bool scsi_generic_pr_register(SCSIDevice *s, uint64_t key, Error **errp)
ret = scsi_SG_IO(s->conf.blk, SG_DXFER_TO_DEV, cmd, sizeof(cmd),
buf, sizeof(buf), s->io_timeout, errp);
if (ret < 0) {
error_prepend(errp, "PERSISTENT RESERVE OUT with REGISTER");
error_prepend(errp, "PERSISTENT RESERVE OUT with REGISTER: ");
return false;
}
return true;
@@ -453,6 +453,16 @@ static bool scsi_generic_pr_preempt(SCSIDevice *s, uint64_t key,
uint64_t key_be = cpu_to_be64(key);
int ret;
/*
* The LIO iSCSI target in Linux up to at least version 7.0 rejects PREEMPT
* commands with a zero TYPE field although the SPC-6 specification says
* the field should be ignored when there is no persistent reservation.
* Work around this by choosing an arbitrary valid PR type value.
*/
if (resv_type == 0) {
resv_type = PR_TYPE_WRITE_EXCLUSIVE;
}
cmd[0] = PERSISTENT_RESERVE_OUT;
cmd[1] = PRO_PREEMPT;
cmd[2] = resv_type & 0xf;
@@ -463,7 +473,7 @@ static bool scsi_generic_pr_preempt(SCSIDevice *s, uint64_t key,
ret = scsi_SG_IO(s->conf.blk, SG_DXFER_TO_DEV, cmd, sizeof(cmd),
buf, sizeof(buf), s->io_timeout, errp);
if (ret < 0) {
error_prepend(errp, "PERSISTENT RESERVE OUT with PREEMPT");
error_prepend(errp, "PERSISTENT RESERVE OUT with PREEMPT: ");
return false;
}
return true;
@@ -503,6 +513,16 @@ bool scsi_generic_pr_state_preempt(SCSIDevice *s, Error **errp)
if (!scsi_generic_pr_preempt(s, key, resv_type, errp)) {
return false;
}
/*
* Some SCSI targets, like the Linux LIO target, remove our
* registration when preempting without a reservation (resv_type is 0).
* Try to register again but ignore the error since a RESERVATION
* CONFLICT is expected if our registration remained in place.
*/
if (resv_type == 0) {
scsi_generic_pr_register(s, key, NULL);
}
}
return true;
}
+56 -1
View File
@@ -392,9 +392,18 @@ static void
pvscsi_cmp_ring_put(PVSCSIState *s, struct PVSCSIRingCmpDesc *cmp_desc)
{
hwaddr cmp_descr_pa;
PVSCSIRingCmpDesc cmp_desc_conv;
cmp_descr_pa = pvscsi_ring_pop_cmp_descr(&s->rings);
trace_pvscsi_cmp_ring_put(cmp_descr_pa);
cmp_desc_conv = (struct PVSCSIRingCmpDesc) {
.context = cpu_to_le64(cmp_desc->context),
.dataLen = cpu_to_le64(cmp_desc->dataLen),
.senseLen = cpu_to_le32(cmp_desc->senseLen),
.hostStatus = cpu_to_le16(cmp_desc->hostStatus),
.scsiStatus = cpu_to_le16(cmp_desc->scsiStatus),
};
cmp_desc = &cmp_desc_conv;
cpu_physical_memory_write(cmp_descr_pa, cmp_desc, sizeof(*cmp_desc));
}
@@ -402,9 +411,18 @@ static void
pvscsi_msg_ring_put(PVSCSIState *s, struct PVSCSIRingMsgDesc *msg_desc)
{
hwaddr msg_descr_pa;
PVSCSIRingMsgDesc msg_desc_conv;
int i;
msg_descr_pa = pvscsi_ring_pop_msg_descr(&s->rings);
trace_pvscsi_msg_ring_put(msg_descr_pa);
msg_desc_conv = (PVSCSIRingMsgDesc) {
.type = cpu_to_le32(msg_desc->type),
};
for (i = 0; i < ARRAY_SIZE(msg_desc->args); i++) {
msg_desc_conv.args[i] = cpu_to_le32(msg_desc->args[i]);
}
msg_desc = &msg_desc_conv;
cpu_physical_memory_write(msg_descr_pa, msg_desc, sizeof(*msg_desc));
}
@@ -481,6 +499,9 @@ pvscsi_get_next_sg_elem(PVSCSISGState *sg)
struct PVSCSISGElement elem;
cpu_physical_memory_read(sg->elemAddr, &elem, sizeof(elem));
elem.addr = le64_to_cpu(elem.addr);
elem.length = le32_to_cpu(elem.length);
elem.flags = le32_to_cpu(elem.flags);
if ((elem.flags & ~PVSCSI_KNOWN_FLAGS) != 0) {
/*
* There is PVSCSI_SGE_FLAG_CHAIN_ELEMENT flag described in
@@ -759,6 +780,12 @@ pvscsi_process_io(PVSCSIState *s)
trace_pvscsi_process_io(next_descr_pa);
cpu_physical_memory_read(next_descr_pa, &descr, sizeof(descr));
descr.context = le64_to_cpu(descr.context);
descr.dataAddr = le64_to_cpu(descr.dataAddr);
descr.dataLen = le64_to_cpu(descr.dataLen);
descr.senseAddr = le64_to_cpu(descr.senseAddr);
descr.senseLen = le32_to_cpu(descr.senseLen);
descr.flags = le32_to_cpu(descr.flags);
pvscsi_process_request_descriptor(s, &descr);
}
@@ -808,6 +835,17 @@ pvscsi_on_cmd_setup_rings(PVSCSIState *s)
{
PVSCSICmdDescSetupRings *rc =
(PVSCSICmdDescSetupRings *) s->curr_cmd_data;
PVSCSICmdDescSetupRings translated;
int i;
translated.reqRingNumPages = le32_to_cpu(rc->reqRingNumPages);
translated.cmpRingNumPages = le32_to_cpu(rc->cmpRingNumPages);
translated.ringsStatePPN = le64_to_cpu(rc->ringsStatePPN);
for (i = 0; i < PVSCSI_SETUP_RINGS_MAX_NUM_PAGES; i++) {
translated.reqRingPPNs[i] = le64_to_cpu(rc->reqRingPPNs[i]);
translated.cmpRingPPNs[i] = le64_to_cpu(rc->cmpRingPPNs[i]);
}
rc = &translated;
trace_pvscsi_on_cmd_arrived("PVSCSI_CMD_SETUP_RINGS");
@@ -831,6 +869,11 @@ pvscsi_on_cmd_abort(PVSCSIState *s)
PVSCSICmdDescAbortCmd *cmd = (PVSCSICmdDescAbortCmd *) s->curr_cmd_data;
PVSCSIRequest *r, *next;
PVSCSICmdDescAbortCmd translated = *cmd;
translated.context = le32_to_cpu(cmd->context);
translated.target = le32_to_cpu(cmd->target);
cmd = &translated;
trace_pvscsi_on_cmd_abort(cmd->context, cmd->target);
QTAILQ_FOREACH_SAFE(r, &s->pending_queue, next, next) {
@@ -862,6 +905,10 @@ pvscsi_on_cmd_reset_device(PVSCSIState *s)
(struct PVSCSICmdDescResetDevice *) s->curr_cmd_data;
SCSIDevice *sdev;
PVSCSICmdDescResetDevice translated = *cmd;
translated.target = le32_to_cpu(cmd->target);
cmd = &translated;
sdev = pvscsi_device_find(s, 0, cmd->target, cmd->lun, &target_lun);
trace_pvscsi_on_cmd_reset_dev(cmd->target, (int) target_lun, sdev);
@@ -892,6 +939,14 @@ pvscsi_on_cmd_setup_msg_ring(PVSCSIState *s)
{
PVSCSICmdDescSetupMsgRing *rc =
(PVSCSICmdDescSetupMsgRing *) s->curr_cmd_data;
PVSCSICmdDescSetupMsgRing translated = *rc;
int i;
translated.numPages = le32_to_cpu(rc->numPages);
for (i = 0; i < PVSCSI_SETUP_MSG_RING_MAX_NUM_PAGES; i++) {
translated.ringPPNs[i] = le64_to_cpu(rc->ringPPNs[i]);
}
rc = &translated;
trace_pvscsi_on_cmd_arrived("PVSCSI_CMD_SETUP_MSG_RING");
@@ -994,7 +1049,7 @@ pvscsi_on_command_data(PVSCSIState *s, uint32_t value)
size_t bytes_arrived = s->curr_cmd_data_cntr * sizeof(uint32_t);
assert(bytes_arrived < sizeof(s->curr_cmd_data));
s->curr_cmd_data[s->curr_cmd_data_cntr++] = value;
s->curr_cmd_data[s->curr_cmd_data_cntr++] = cpu_to_le32(value);
pvscsi_do_command_processing(s);
}
+14
View File
@@ -108,6 +108,20 @@ enum PVSCSICommands {
#define PVSCSI_COMMAND_PROCESSING_FAILED (-1)
#define PVSCSI_COMMAND_NOT_ENOUGH_DATA (-2)
/*
* About endianess for the below structs:
*
* These structs are used to describe the data that is exchanged between the
* guest and the PVSCSI device. The endianess of the fields in these structs
* is not defined by any standard. The current implemented drivers are designed
* to only work on x86 architecture, so there is no endianess awareness in the
* drivers and thus we have no idea whether the fields should be in little-
* endian or target native endian format.
*
* Considering the above, we assume that PVSCSI is implicitly little-endian and
* expect the fields in these structs to be in little-endian format.
*/
/*
* Command descriptor for PVSCSI_CMD_RESET_DEVICE --
*/
+1 -1
View File
@@ -137,7 +137,7 @@ static void niagara_init(MachineState *machine)
outside of the partition RAM */
if (dinfo) {
BlockBackend *blk = blk_by_legacy_dinfo(dinfo);
int size = blk_getlength(blk);
int64_t size = blk_getlength(blk);
if (size > 0) {
memory_region_init_ram(&s->vdisk_ram, NULL, "sun4v_vdisk.ram", size,
&error_fatal);
+1 -4
View File
@@ -416,10 +416,7 @@ static void ufs_lu_unrealize(DeviceState *dev)
{
UfsLu *lu = DO_UPCAST(UfsLu, qdev, dev);
if (lu->scsi_dev) {
object_unref(OBJECT(lu->scsi_dev));
lu->scsi_dev = NULL;
}
lu->scsi_dev = NULL;
}
static void ufs_lu_class_init(ObjectClass *oc, const void *data)
+4
View File
@@ -252,6 +252,10 @@ static int usb_mouse_poll(USBWacomState *s, uint8_t *buf, int len)
if (s->buttons_state & MOUSE_EVENT_MBUTTON)
b |= 0x04;
if (len < 3) {
return 0;
}
buf[0] = b;
buf[1] = dx;
buf[2] = dy;
+10
View File
@@ -28,6 +28,7 @@
#include "qemu/osdep.h"
#include "hw/core/irq.h"
#include "qapi/error.h"
#include "qemu/log.h"
#include "qemu/module.h"
#include "qemu/timer.h"
#include "hw/usb/usb.h"
@@ -1130,6 +1131,8 @@ static int ohci_service_ed_list(OHCIState *ohci, uint32_t head)
return 0;
}
for (cur = head; cur && link_cnt++ < ED_LINK_LIMIT; cur = next_ed) {
unsigned int ed_cnt = 0;
if (ohci_read_ed(ohci, cur, &ed)) {
trace_usb_ohci_ed_read_error(cur);
ohci_die(ohci);
@@ -1173,6 +1176,13 @@ static int ohci_service_ed_list(OHCIState *ohci, uint32_t head)
break;
}
}
if (ed_cnt++ > ED_LINK_LIMIT) {
qemu_log_mask(LOG_GUEST_ERROR,
"ohci: Too many endpoint descriptors in loop\n");
ohci_die(ohci);
return 0;
}
}
if (ohci_put_ed(ohci, cur, &ed)) {
+12
View File
@@ -196,6 +196,18 @@ static void usb_xhci_pci_exit(PCIDevice *dev)
&& dev->msix_entry_used) {
msix_uninit(dev, &s->xhci.mem, &s->xhci.mem);
}
/*
* The embedded xhci-core child holds a strong "host" link back to this
* PCI device (set in usb_xhci_pci_realize()), forming a refcount cycle:
* the PCI device owns the child, and the child's strong link pins the PCI
* device. On unplug, object_unparent() only drops the parent/bus refs, so
* the link ref keeps this device at refcount 1 forever and
* device_finalize() never runs. Unrealize the child first (so the
* realized-check in set_link passes), then clear the link to break the
* cycle.
*/
qdev_unrealize(DEVICE(&s->xhci));
object_property_set_link(OBJECT(&s->xhci), "host", NULL, &error_abort);
}
static const VMStateDescription vmstate_xhci_pci = {
+1
View File
@@ -20,6 +20,7 @@ static bool xhci_sysbus_intr_raise(XHCIState *xhci, int n, bool level)
{
XHCISysbusState *s = container_of(xhci, XHCISysbusState, xhci);
assert(n < xhci->numintrs);
qemu_set_irq(s->irq[n], level);
return false;
+24 -4
View File
@@ -965,11 +965,13 @@ static TRBCCode xhci_alloc_device_streams(XHCIState *xhci, unsigned int slotid,
* together and make an usb_device_alloc_streams call per group.
*/
if (epctxs[i]->nr_pstreams != req_nr_streams) {
FIXME("guest streams config not identical for all eps");
qemu_log_mask(LOG_UNIMP,
"guest streams config not identical for all eps\n");
return CC_RESOURCE_ERROR;
}
if (eps[i]->max_streams != dev_max_streams) {
FIXME("device streams config not identical for all eps");
qemu_log_mask(LOG_UNIMP,
"device streams config not identical for all eps\n");
return CC_RESOURCE_ERROR;
}
}
@@ -1009,7 +1011,12 @@ static XHCIStreamContext *xhci_find_stream(XHCIEPContext *epctx,
dma_addr_t base;
uint32_t ctx[2], sct;
assert(streamid != 0);
if (!streamid) {
qemu_log_mask(LOG_GUEST_ERROR, "xhci: stream ID is zero\n");
*cc_error = CC_INVALID_STREAM_ID_ERROR;
return NULL;
}
if (epctx->lsa) {
if (streamid >= epctx->nr_pstreams) {
*cc_error = CC_INVALID_STREAM_ID_ERROR;
@@ -1120,7 +1127,7 @@ static void xhci_init_epctx(XHCIEPContext *epctx,
epctx->ring.ccs = ctx[2] & 1;
}
epctx->interval = 1 << ((ctx[0] >> 16) & 0xff);
epctx->interval = 1u << MIN((ctx[0] >> 16) & 0xffu, 18u);
}
static TRBCCode xhci_enable_ep(XHCIState *xhci, unsigned int slotid,
@@ -3040,6 +3047,12 @@ static uint64_t xhci_runtime_read(void *ptr, hwaddr reg,
}
} else {
int v = (reg - 0x20) / 0x20;
if (v >= xhci->numintrs) {
qemu_log_mask(LOG_GUEST_ERROR,
"xhci: read from nonexistent interrupter %i\n", v);
goto out_trace;
}
XHCIInterrupter *intr = &xhci->intr[v];
switch (reg & 0x1f) {
case 0x00: /* IMAN */
@@ -3066,6 +3079,7 @@ static uint64_t xhci_runtime_read(void *ptr, hwaddr reg,
}
}
out_trace:
trace_usb_xhci_runtime_read(reg, ret);
return ret;
}
@@ -3083,7 +3097,13 @@ static void xhci_runtime_write(void *ptr, hwaddr reg,
trace_usb_xhci_unimplemented("runtime write", reg);
return;
}
v = (reg - 0x20) / 0x20;
if (v >= xhci->numintrs) {
qemu_log_mask(LOG_GUEST_ERROR,
"xhci: write to nonexistent interrupter %i\n", v);
return;
}
intr = &xhci->intr[v];
switch (reg & 0x1f) {
+41 -1
View File
@@ -690,6 +690,7 @@ static void usbredir_buffered_bulk_in_complete_ftdi(USBRedirDevice *dev,
struct buf_packet *bulkp;
int count;
assert(maxp != 0);
while ((bulkp = QTAILQ_FIRST(&dev->endpoint[EP2I(ep)].bufpq)) &&
p->actual_length < p->iov.size && p->status == USB_RET_SUCCESS) {
if (bulkp->len < 2) {
@@ -739,6 +740,7 @@ static void usbredir_handle_buffered_bulk_in_data(USBRedirDevice *dev,
.stream_id = 0,
.no_transfers = 5,
};
assert(dev->endpoint[EP2I(ep)].max_packet_size != 0);
/* Round bytes_per_transfer up to a multiple of max_packet_size */
bpt = 512 + dev->endpoint[EP2I(ep)].max_packet_size - 1;
bpt /= dev->endpoint[EP2I(ep)].max_packet_size;
@@ -793,6 +795,7 @@ static void usbredir_handle_bulk_data(USBRedirDevice *dev, USBPacket *p,
}
if (dev->endpoint[EP2I(ep)].bulk_receiving_enabled) {
assert(maxp != 0);
if (size != 0 && (size % maxp) == 0) {
usbredir_handle_buffered_bulk_in_data(dev, p, ep);
return;
@@ -1801,6 +1804,17 @@ static void usbredir_ep_info(void *priv,
if (usbredirparser_peer_has_cap(dev->parser,
usb_redir_cap_ep_info_max_packet_size)) {
dev->endpoint[i].max_packet_size = ep_info->max_packet_size[i];
if (ep_info->max_packet_size[i] == 0 &&
dev->endpoint[i].bulk_receiving_enabled) {
USBPacket *p = dev->endpoint[i].pending_async_packet;
usbredir_stop_bulk_receiving(dev, I2EP(i));
dev->endpoint[i].bulk_receiving_enabled = 0;
if (p != NULL) {
dev->endpoint[i].pending_async_packet = NULL;
p->status = USB_RET_IOERROR;
usb_packet_complete(&dev->dev, p);
}
}
}
#if USBREDIR_VERSION >= 0x000700
if (usbredirparser_peer_has_cap(dev->parser,
@@ -2143,7 +2157,7 @@ static void usbredir_buffered_bulk_packet(void *priv, uint64_t id,
USBRedirDevice *dev = priv;
uint8_t status, ep = buffered_bulk_packet->endpoint;
void *free_on_destroy;
int i, len;
int i, len, queued = 0;
DPRINTF("buffered-bulk-in status %d ep %02X len %d id %"PRIu64"\n",
buffered_bulk_packet->status, ep, data_len, id);
@@ -2161,6 +2175,7 @@ static void usbredir_buffered_bulk_packet(void *priv, uint64_t id,
}
/* Data must be in maxp chunks for buffered_bulk_add_*_data_to_packet */
assert(dev->endpoint[EP2I(ep)].max_packet_size != 0);
len = dev->endpoint[EP2I(ep)].max_packet_size;
status = usb_redir_success;
free_on_destroy = NULL;
@@ -2174,8 +2189,24 @@ static void usbredir_buffered_bulk_packet(void *priv, uint64_t id,
/* bufp_alloc also adds the packet to the ep queue */
r = bufp_alloc(dev, data + i, len, status, ep, free_on_destroy);
if (r) {
/*
* Earlier fragments from this packet are in the queue
* with interior pointers into data. If the dropped
* fragment was the final one, bufp_alloc already freed
* data so those pointers are dangling. Remove them.
*/
while (queued > 0) {
struct buf_packet *bufp;
bufp = QTAILQ_LAST(&dev->endpoint[EP2I(ep)].bufpq);
bufp_free(dev, bufp, ep);
queued--;
}
if (!free_on_destroy) {
free(data);
}
break;
}
queued++;
}
if (dev->endpoint[EP2I(ep)].pending_async_packet) {
@@ -2228,6 +2259,15 @@ static int usbredir_post_load(void *priv, int version_id)
usbredir_setup_usb_eps(dev);
usbredir_check_bulk_receiving(dev);
for (int i = 0; i < MAX_ENDPOINTS; i++) {
if (dev->endpoint[i].bulk_receiving_started &&
dev->endpoint[i].max_packet_size == 0) {
error_report("usbredir: endpoint %d has bulk receiving started "
"with zero max_packet_size", i);
return -EINVAL;
}
}
return 0;
}
+2 -1
View File
@@ -173,6 +173,7 @@ static void vhost_vdpa_device_unrealize(DeviceState *dev)
{
VirtIODevice *vdev = VIRTIO_DEVICE(dev);
VhostVdpaDevice *s = VHOST_VDPA_DEVICE(vdev);
struct vhost_virtqueue *vqs = s->dev.vqs;
int i;
virtio_set_status(vdev, 0);
@@ -184,8 +185,8 @@ static void vhost_vdpa_device_unrealize(DeviceState *dev)
virtio_cleanup(vdev);
g_free(s->config);
g_free(s->dev.vqs);
vhost_dev_cleanup(&s->dev);
g_free(vqs);
g_free(s->vdpa.shared);
qemu_close(s->vhostfd);
s->vhostfd = -1;
+4 -3
View File
@@ -27,12 +27,13 @@
/*
* Allow some level of source compatibility with softmmu.
* Invalid is set when the page does not have requested permissions.
* MMIO is set when we want the target helper to use the functional
* INVALID is set when the page does not have requested permissions.
* FORCE_SLOW is set when we want the target helper to use the functional
* interface for load/store so that plugins see the access.
*/
#define TLB_INVALID_MASK (1 << 0)
#define TLB_MMIO (1 << 1)
#define TLB_FORCE_SLOW (1 << 1)
#define TLB_MMIO 0
#define TLB_WATCHPOINT 0
#else
+3
View File
@@ -18,6 +18,9 @@
typedef struct SysemuCPUOps {
/**
* @has_work: Callback for checking if there is work to do.
*
* This function should be idempotent (i.e. not change state) as
* it will likely be queried multiple times before a CPU resumes.
*/
bool (*has_work)(CPUState *cpu); /* MANDATORY NON-NULL */
/**
+5 -1
View File
@@ -65,7 +65,11 @@
#define STM32_RCC_NREGS ((STM32_RCC_DCKCFGR2 >> 2) + 1)
#define STM32_RCC_PERIPHERAL_SIZE 0x400
#define STM32_RCC_NIRQS (32 * 5) /* 32 bits per reg, 5 en/rst regs */
/* 32 bits per reg, 3 AHB regs and 2 APB regs */
#define STM32_RCC_N_AHB_IRQS (32 * 3)
#define STM32_RCC_N_APB_IRQS (32 * 2)
#define STM32_RCC_NIRQS (STM32_RCC_N_AHB_IRQS + STM32_RCC_N_APB_IRQS)
#define STM32_RCC_GPIO_IRQ_OFFSET 0
+1
View File
@@ -132,6 +132,7 @@ struct SubchDev {
bool ccw_fmt_1;
bool thinint_active;
uint8_t ccw_no_data_cnt;
uint8_t ccw_tic_cnt;
uint16_t migrated_schid; /* used for mismatch detection */
CcwDataStream cds;
/* transport-provided data: */
+9
View File
@@ -15,6 +15,7 @@
#define HW_VIRTIO_GPU_H
#include "qemu/queue.h"
#include "qemu/units.h"
#include "ui/qemu-pixman.h"
#include "ui/console.h"
#include "hw/virtio/virtio.h"
@@ -299,6 +300,14 @@ struct VirtIOGPURutabaga {
struct rutabaga *rutabaga;
};
/*
* With 4 KiB pages and QEMU's VIRTQUEUE_MAX_SIZE (1024) mapped-iov
* limit, the largest inline command is ~4 MiB. Cap submit_3d
* allocations to this value to prevent a malicious guest from
* triggering an OOM abort via an inflated cs.size field.
*/
#define VIRTIO_GPU_MAX_CMD_SUBMIT_SIZE (4 * MiB)
#define VIRTIO_GPU_FILL_CMD(out) do { \
size_t virtiogpufillcmd_s_ = \
iov_to_buf(cmd->elem.out_sg, cmd->elem.out_num, 0, \
+23
View File
@@ -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
+10
View File
@@ -340,4 +340,14 @@
#define PRO_REGISTER_AND_MOVE 0x07
#define PRO_REPLACE_LOST_RESERVATION 0x08
/*
* Persistent reservation types
*/
#define PR_TYPE_WRITE_EXCLUSIVE 0x1
#define PR_TYPE_EXCLUSIVE_ACCESS 0x3
#define PR_TYPE_WRITE_EXCLUSIVE_REG_ONLY 0x5
#define PR_TYPE_EXCLUSIVE_ACCESS_REG_ONLY 0x6
#define PR_TYPE_WRITE_EXCLUSIVE_ALL_REGS 0x7
#define PR_TYPE_EXCLUSIVE_ACCESS_ALL_REGS 0x8
#endif
+23
View File
@@ -3,8 +3,31 @@
#include "qemu/osdep.h"
#include "qemu.h"
#include "loader.h"
#include "target_elf.h"
abi_ulong get_elf_hwcap(CPUState *cs)
{
/*
* The Linux kernel computes ELF_HWCAP as ~amask(-1), which clears a bit
* for each supported ISA extension. env->amask stores exactly those bits
* set for the extensions supported by the emulated CPU model, matching
* the kernel's convention: bit set in AT_HWCAP ↔ extension present.
*/
return cpu_env(cs)->amask;
}
void elf_core_copy_regs(target_elf_gregset_t *r, const CPUAlphaState *env)
{
int i;
for (i = 0; i < 31; i++) {
r->regs[i] = tswap64(env->ir[i]);
}
r->pc = tswap64(env->pc);
r->unique = tswap64(env->unique);
}
const char *get_elf_cpu_model(uint32_t eflags)
{
return "ev67";
+14
View File
@@ -11,4 +11,18 @@
#define ELF_CLASS ELFCLASS64
#define ELF_MACHINE EM_ALPHA
#define HAVE_ELF_CORE_DUMP 1
#define HAVE_ELF_HWCAP 1
/*
* Matches the kernel's elf_gregset_t (ELF_NGREG = 33):
* r0-r30 at indices 0-30, pc at 31, ps at 32.
* r31 (hardwired zero) is not stored; pc occupies index 31.
*/
typedef struct target_elf_gregset_t {
abi_ulong regs[31]; /* integer registers r0-r30 [0..30] */
abi_ulong pc; /* program counter [31] */
abi_ulong unique; /* thread's UNIQUE field [32] */
} target_elf_gregset_t;
#endif
+26 -4
View File
@@ -5088,6 +5088,9 @@ do_ioctl_usbdevfs_submiturb(const IOCTLEntry *ie, uint8_t *buf_temp,
}
#endif /* CONFIG_USBFS */
#define DM_MAX_TARGETS 1048576
#define DM_MAX_TARGET_PARAMS 1024
static abi_long do_ioctl_dm(const IOCTLEntry *ie, uint8_t *buf_temp, int fd,
int cmd, abi_long arg)
{
@@ -5100,6 +5103,7 @@ static abi_long do_ioctl_dm(const IOCTLEntry *ie, uint8_t *buf_temp, int fd,
abi_long ret;
void *big_buf = NULL;
char *host_data;
const size_t minimum_data_size = offsetof(struct dm_ioctl, data);
arg_type++;
target_size = thunk_type_size(arg_type, 0);
@@ -5111,9 +5115,26 @@ static abi_long do_ioctl_dm(const IOCTLEntry *ie, uint8_t *buf_temp, int fd,
thunk_convert(buf_temp, argptr, arg_type, THUNK_HOST);
unlock_user(argptr, arg, 0);
/* buf_temp is too small, so fetch things into a bigger buffer */
big_buf = g_malloc0(((struct dm_ioctl*)buf_temp)->data_size * 2);
memcpy(big_buf, buf_temp, target_size);
/* At this point this includes the size of the fixed dm_ioctl parts */
guest_data_size = ((struct dm_ioctl *)buf_temp)->data_size;
if (guest_data_size < minimum_data_size ||
guest_data_size > DM_MAX_TARGETS * DM_MAX_TARGET_PARAMS) {
ret = -TARGET_EINVAL;
goto out;
}
/*
* buf_temp is too small, so fetch things into a bigger buffer. Here
* we copy all of the fixed parts of struct dm_ioctl but not the
* data at the end (which in the struct is "char data[7]" but in
* reality is command-specific and might be nothing or might be
* much larger, as defined by data_size). We know struct dm_ioctl's
* size is not target specific so we don't need to distinguish between
* its minimum size for the host vs the target.
*/
big_buf = g_malloc0(guest_data_size * 2);
memcpy(big_buf, buf_temp, minimum_data_size);
buf_temp = big_buf;
host_dm = big_buf;
@@ -5122,7 +5143,8 @@ static abi_long do_ioctl_dm(const IOCTLEntry *ie, uint8_t *buf_temp, int fd,
ret = -TARGET_EINVAL;
goto out;
}
guest_data_size = host_dm->data_size - host_dm->data_start;
/* Adjust down to only the size of the payload */
guest_data_size -= host_dm->data_start;
host_data = (char*)host_dm + host_dm->data_start;
argptr = lock_user(VERIFY_READ, guest_data, guest_data_size, 1);
+1
View File
@@ -4471,6 +4471,7 @@ foreach target : target_dirs
emulators += {exe['name'] : custom_target(exe['name'],
input: build_input,
output: exe['name'],
build_by_default: true,
command: [entitlement, '@OUTPUT@', '@INPUT@'])
}
+3 -1
View File
@@ -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;
@@ -1385,7 +1385,9 @@ void show_netdevs(void)
"dgram",
"hubport",
"tap",
#ifdef CONFIG_PASST
"passt",
#endif
#ifdef CONFIG_SLIRP
"user",
#endif
+20 -8
View File
@@ -1914,19 +1914,19 @@ ERST
DEF("fsdev", HAS_ARG, QEMU_OPTION_fsdev,
"-fsdev local,id=id,path=path,security_model=mapped-xattr|mapped-file|passthrough|none\n"
" [,writeout=immediate][,readonly=on][,fmode=fmode][,dmode=dmode]\n"
" [,writeout=immediate][,readonly=on][,fmode=fmode][,dmode=dmode][,max_xattr=max]\n"
" [[,throttling.bps-total=b]|[[,throttling.bps-read=r][,throttling.bps-write=w]]]\n"
" [[,throttling.iops-total=i]|[[,throttling.iops-read=r][,throttling.iops-write=w]]]\n"
" [[,throttling.bps-total-max=bm]|[[,throttling.bps-read-max=rm][,throttling.bps-write-max=wm]]]\n"
" [[,throttling.iops-total-max=im]|[[,throttling.iops-read-max=irm][,throttling.iops-write-max=iwm]]]\n"
" [[,throttling.iops-size=is]]\n"
"-fsdev synth,id=id\n",
"-fsdev synth,id=id[,max_xattr=max]\n",
QEMU_ARCH_ALL)
SRST
``-fsdev local,id=id,path=path,security_model=security_model [,writeout=writeout][,readonly=on][,fmode=fmode][,dmode=dmode] [,throttling.option=value[,throttling.option=value[,...]]]``
``-fsdev local,id=id,path=path,security_model=security_model [,writeout=writeout][,readonly=on][,fmode=fmode][,dmode=dmode][,max_xattr=max] [,throttling.option=value[,throttling.option=value[,...]]]``
\
``-fsdev synth,id=id[,readonly=on]``
``-fsdev synth,id=id[,readonly=on][,max_xattr=max]``
Define a new file system device. Valid options are:
``local``
@@ -2000,6 +2000,12 @@ SRST
Let every is bytes of a request count as a new request for iops
throttling purposes.
``max_xattr=max``
Specifies the maximum number of concurrent xattr FIDs allowed for
this export. The default is 1024. Set to 0 for allowing an infinite
number of xattr FIDs. This limit prevents host memory exhaustion
attacks by capping the number of simultaneous xattr FIDs.
-fsdev option is used along with -device driver "virtio-9p-...".
``-device virtio-9p-type,fsdev=id,mount_tag=mount_tag``
@@ -2019,14 +2025,14 @@ ERST
DEF("virtfs", HAS_ARG, QEMU_OPTION_virtfs,
"-virtfs local,path=path,mount_tag=tag,security_model=mapped-xattr|mapped-file|passthrough|none\n"
" [,id=id][,writeout=immediate][,readonly=on][,fmode=fmode][,dmode=dmode][,multidevs=remap|forbid|warn]\n"
"-virtfs synth,mount_tag=tag[,id=id][,readonly=on]\n",
" [,id=id][,writeout=immediate][,readonly=on][,fmode=fmode][,dmode=dmode][,multidevs=remap|forbid|warn][,max_xattr=max]\n"
"-virtfs synth,mount_tag=tag[,id=id][,readonly=on][,max_xattr=max]\n",
QEMU_ARCH_ALL)
SRST
``-virtfs local,path=path,mount_tag=mount_tag ,security_model=security_model[,writeout=writeout][,readonly=on] [,fmode=fmode][,dmode=dmode][,multidevs=multidevs]``
``-virtfs local,path=path,mount_tag=mount_tag ,security_model=security_model[,writeout=writeout][,readonly=on] [,fmode=fmode][,dmode=dmode][,multidevs=multidevs][,max_xattr=max]``
\
``-virtfs synth,mount_tag=mount_tag``
``-virtfs synth,mount_tag=mount_tag[,max_xattr=max]``
Define a new virtual filesystem device and expose it to the guest using
a virtio-9p-device (a.k.a. 9pfs), which essentially means that a certain
directory on host is made directly accessible by guest as a pass-through
@@ -2092,6 +2098,12 @@ SRST
Specifies the tag name to be used by the guest to mount this
export point.
``max_xattr=max``
Specifies the maximum number of concurrent xattr FIDs allowed for
this export. The default is 1024. Set to 0 for allowing an infinite
number of xattr FIDs. This limit prevents host memory exhaustion
attacks by capping the number of simultaneous xattr FIDs.
``multidevs=remap|forbid|warn``
Specifies how to deal with multiple devices being shared with
the same 9p export in order to avoid file ID collisions on guest.
+12 -11
View File
@@ -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)
+6 -1
View File
@@ -3254,7 +3254,7 @@ void qemu_init(int argc, char **argv)
QemuOpts *fsdev;
QemuOpts *device;
const char *writeout, *sock_fd, *socket, *path, *security_model,
*multidevs;
*multidevs, *max_xattr_str;
olist = qemu_find_opts("virtfs");
if (!olist) {
@@ -3318,6 +3318,11 @@ void qemu_init(int argc, char **argv)
if (multidevs) {
qemu_opt_set(fsdev, "multidevs", multidevs, &error_abort);
}
max_xattr_str = qemu_opt_get(opts, "max_xattr");
if (max_xattr_str) {
qemu_opt_set(fsdev, "max_xattr", max_xattr_str,
&error_abort);
}
device = qemu_opts_create(qemu_find_opts("device"), NULL, 0,
&error_abort);
qemu_opt_set(device, "driver", "virtio-9p-pci", &error_abort);
+3 -3
View File
@@ -78,7 +78,7 @@ static void arm_set_cpu_on_async_work(CPUState *target_cpu_state,
/* Finally set the power status */
assert(bql_locked());
target_cpu->power_state = PSCI_ON;
arm_set_cpu_power_state(target_cpu, PSCI_ON);
}
int arm_set_cpu_on(uint64_t cpuid, uint64_t entry, uint64_t context_id,
@@ -186,7 +186,7 @@ static void arm_set_cpu_on_and_reset_async_work(CPUState *target_cpu_state,
/* Finally set the power status */
assert(bql_locked());
target_cpu->power_state = PSCI_ON;
arm_set_cpu_power_state(target_cpu, PSCI_ON);
}
int arm_set_cpu_on_and_reset(uint64_t cpuid)
@@ -239,7 +239,7 @@ static void arm_set_cpu_off_async_work(CPUState *target_cpu_state,
ARMCPU *target_cpu = ARM_CPU(target_cpu_state);
assert(bql_locked());
target_cpu->power_state = PSCI_OFF;
arm_set_cpu_power_state(target_cpu, PSCI_OFF);
target_cpu_state->halted = 1;
target_cpu_state->exception_index = EXCP_HLT;
}
+29 -11
View File
@@ -144,18 +144,34 @@ static bool arm_cpu_has_work(CPUState *cs)
{
ARMCPU *cpu = ARM_CPU(cs);
if (arm_feature(&cpu->env, ARM_FEATURE_M)) {
if (cpu->env.event_register) {
return true;
}
/*
* Only another PSCI call can wake the CPU up in which case the
* power_state would be set by arm_set_cpu_on_and_reset_async_work()
*/
if (cpu->power_state == PSCI_OFF) {
g_assert(cpu->env.halt_reason == HALT_PSCI);
return false;
}
return (cpu->power_state != PSCI_OFF)
&& cpu_test_interrupt(cs,
CPU_INTERRUPT_FIQ | CPU_INTERRUPT_HARD
| CPU_INTERRUPT_NMI | CPU_INTERRUPT_VINMI | CPU_INTERRUPT_VFNMI
| CPU_INTERRUPT_VFIQ | CPU_INTERRUPT_VIRQ | CPU_INTERRUPT_VSERR
| CPU_INTERRUPT_EXITTB);
/*
* A wake-up event should only wake us if we are halted on a WFE
*/
if (cpu->env.halt_reason == HALT_WFE && cpu->env.event_register) {
return true;
}
/*
* Otherwise pretty much any IRQ would wake us up
*/
if (cpu_test_interrupt(cs,
CPU_INTERRUPT_FIQ | CPU_INTERRUPT_HARD
| CPU_INTERRUPT_NMI | CPU_INTERRUPT_VINMI | CPU_INTERRUPT_VFNMI
| CPU_INTERRUPT_VFIQ | CPU_INTERRUPT_VIRQ | CPU_INTERRUPT_VSERR
| CPU_INTERRUPT_EXITTB)) {
return true;
}
return false;
}
#endif /* !CONFIG_USER_ONLY */
@@ -250,7 +266,7 @@ static void arm_cpu_reset_hold(Object *obj, ResetType type)
env->vfp.xregs[ARM_VFP_MVFR1] = cpu->isar.mvfr1;
env->vfp.xregs[ARM_VFP_MVFR2] = cpu->isar.mvfr2;
cpu->power_state = cs->start_powered_off ? PSCI_OFF : PSCI_ON;
arm_set_cpu_power_state(cpu, cs->start_powered_off ? PSCI_OFF : PSCI_ON);
if (arm_feature(env, ARM_FEATURE_AARCH64)) {
/* 64 bit CPUs always start in 64 bit mode */
@@ -776,6 +792,8 @@ bool arm_cpu_exec_halt(CPUState *cs)
if (cpu->wfxt_timer) {
timer_del(cpu->wfxt_timer);
}
/* clear the halt reason */
cpu->env.halt_reason = NOT_HALTED;
}
return leave_halt;
}
+16
View File
@@ -257,6 +257,19 @@ typedef enum ARMFPStatusFlavour {
} ARMFPStatusFlavour;
#define FPST_COUNT 10
/**
* ARMHaltReason - the reason we have entered halt state
*
* To be able to correctly wake up via arm_cpu_has_work() we need to
* track the reason we went to sleep.
*/
typedef enum {
NOT_HALTED = 0,
HALT_PSCI,
HALT_WFI,
HALT_WFE
} ARMHaltReason;
typedef struct CPUArchState {
/* Regs for current mode. */
uint32_t regs[16];
@@ -760,6 +773,9 @@ typedef struct CPUArchState {
/* Optional fault info across tlb lookup. */
ARMMMUFaultInfo *tlb_fi;
/* Reason the CPU is halted */
ARMHaltReason halt_reason;
/*
* The event register is shared by all ARM profiles (A/R/M),
* so it is stored in the top-level CPU state.
+11
View File
@@ -1943,4 +1943,15 @@ int compare_u64(const void *a, const void *b);
/* Used in FEAT_MEC to set the MECIDWidthm1 field in the MECIDR_EL2 register. */
#define MECID_WIDTH 16
/**
* arm_set_cpu_power_state() - set power state synced with halt_reason
*/
static inline void arm_set_cpu_power_state(ARMCPU *cpu, ARMPSCIState state)
{
CPUARMState *env = &cpu->env;
cpu->power_state = state;
env->halt_reason = state == PSCI_OFF ? HALT_PSCI : NOT_HALTED;
}
#endif
+3 -2
View File
@@ -1143,11 +1143,12 @@ static int kvm_arm_sync_mpstate_to_qemu(ARMCPU *cpu)
if (cap_has_mp_state) {
struct kvm_mp_state mp_state;
int ret = kvm_vcpu_ioctl(CPU(cpu), KVM_GET_MP_STATE, &mp_state);
ARMPSCIState state;
if (ret) {
return ret;
}
cpu->power_state = (mp_state.mp_state == KVM_MP_STATE_STOPPED) ?
PSCI_OFF : PSCI_ON;
state = (mp_state.mp_state == KVM_MP_STATE_STOPPED) ? PSCI_OFF : PSCI_ON;
arm_set_cpu_power_state(cpu, state);
}
return 0;
}
+1 -1
View File
@@ -916,7 +916,7 @@ static int get_power(QEMUFile *f, void *opaque, size_t size,
{
ARMCPU *cpu = opaque;
bool powered_off = qemu_get_byte(f);
cpu->power_state = powered_off ? PSCI_OFF : PSCI_ON;
arm_set_cpu_power_state(cpu, powered_off ? PSCI_OFF : PSCI_ON);
return 0;
}
+7 -2
View File
@@ -1392,9 +1392,14 @@ static int get_S2prot_indirect(CPUARMState *env, GetPhysAddrResult *result,
PAGE_READ | PAGE_WRITE },
};
uint64_t pir = (env->cp15.scr_el3 & SCR_PIEN ? env->cp15.s2pir_el2 : 0);
int s2pi = extract64(pir, pi_index * 4, 4);
uint64_t pir = env->cp15.s2pir_el2;
int s2pi;
if (arm_feature(env, ARM_FEATURE_EL3) && !(env->cp15.scr_el3 & SCR_PIEN)) {
pir = 0;
}
s2pi = extract64(pir, pi_index * 4, 4);
result->f.prot = perm_table[s2pi][2];
return perm_table[s2pi][s1_is_el0];
}
+3
View File
@@ -403,6 +403,7 @@ void HELPER(wfi)(CPUARMState *env, uint32_t insn_len)
target_el);
}
env->halt_reason = HALT_WFI;
cs->exception_index = EXCP_HLT;
cs->halted = 1;
cpu_loop_exit(cs);
@@ -463,6 +464,7 @@ void HELPER(wfit)(CPUARMState *env, uint64_t timeout)
} else {
timer_mod(cpu->wfxt_timer, nexttick);
}
env->halt_reason = HALT_WFI;
cs->exception_index = EXCP_HLT;
cs->halted = 1;
cpu_loop_exit(cs);
@@ -507,6 +509,7 @@ void HELPER(wfe)(CPUARMState *env)
return;
}
env->halt_reason = HALT_WFE;
cs->exception_index = EXCP_HLT;
cs->halted = 1;
cpu_loop_exit(cs);
+1 -1
View File
@@ -854,7 +854,7 @@ static TLBIRange tlbi_aa64_get_range(CPUARMState *env, ARMMMUIdx mmuidx,
gran = tlbi_range_tg_to_gran_size(page_size_granule);
/* The granule encoded in value must match the granule in use. */
if (gran != param.gran) {
if (gran != param.gran || gran == GranInvalid) {
qemu_log_mask(LOG_GUEST_ERROR, "Invalid tlbi page size granule %d\n",
page_size_granule);
return ret;
+6 -1
View File
@@ -10,6 +10,11 @@
#define TARGET_VIRT_ADDR_SPACE_BITS 48
#define TARGET_PAGE_BITS 12
#ifdef CONFIG_USER_ONLY
/* Allow user-only to vary page size from 4k */
# define TARGET_PAGE_BITS_VARY
#else
# define TARGET_PAGE_BITS 12
#endif
#endif
+8
View File
@@ -1601,10 +1601,18 @@ static int get_physical_address(CPURISCVState *env, hwaddr *physical,
/* Page table updates need to be atomic with MTTCG enabled */
if (updated_pte != pte && !is_debug) {
int pmp_prot, pmp_ret;
if (!adue) {
return TRANSLATE_FAIL;
}
pmp_ret = get_physical_address_pmp(env, &pmp_prot, pte_addr,
sxlen_bytes, MMU_DATA_STORE, PRV_S);
if (pmp_ret != TRANSLATE_SUCCESS) {
return TRANSLATE_PMP_FAIL;
}
/*
* - if accessed or dirty bits need updating, and the PTE is
* in RAM, then we do so atomically with a compare and swap.
+27 -11
View File
@@ -919,7 +919,16 @@ static RISCVException read_vtype(CPURISCVState *env, int csrno,
target_ulong *val)
{
uint64_t vill;
switch (env->xl) {
int xl = env->xl;
/*
* TCG plugins can read registers before env->xl is initialized.
* Fall back to the CPU's maximum XLEN in that early-init case.
*/
if (xl == 0) {
xl = riscv_cpu_mxl(env);
}
switch (xl) {
case MXL_RV32:
vill = (uint32_t)env->vill << 31;
break;
@@ -1982,6 +1991,20 @@ static target_ulong legalize_mpp(CPURISCVState *env, target_ulong old_mpp,
return val;
}
static uint64_t riscv_write_uxl(CPURISCVState *env, uint64_t val,
uint64_t field)
{
RISCVMXL xl = riscv_cpu_mxl(env);
uint64_t uxl = get_field(val, field);
if (uxl == MXL_RV128) {
uxl = xl == MXL_RV128 ? MXL_RV64 : xl;
val = set_field(val, field, uxl);
}
return val;
}
static RISCVException write_mstatus(CPURISCVState *env, int csrno,
target_ulong val, uintptr_t ra)
{
@@ -2028,17 +2051,8 @@ static RISCVException write_mstatus(CPURISCVState *env, int csrno,
if (xl != MXL_RV32 || env->debugger) {
if ((val & MSTATUS64_UXL) != 0) {
uint64_t uxl = val & MSTATUS64_UXL >> 32;
mask |= MSTATUS64_UXL;
/*
* uxl = 3 is reserved so write the current xl instead.
* In case xl = MXL_RV128 (3) write MXL_RV64.
*/
if (uxl == 3) {
uxl = xl == MXL_RV128 ? MXL_RV64 : xl;
val = deposit64(val, 32, 2, uxl);
}
val = riscv_write_uxl(env, val, MSTATUS64_UXL);
}
}
@@ -5146,6 +5160,8 @@ static RISCVException write_vsstatus(CPURISCVState *env, int csrno,
uint64_t mask = (target_ulong)-1;
if ((val & VSSTATUS64_UXL) == 0) {
mask &= ~VSSTATUS64_UXL;
} else {
val = riscv_write_uxl(env, val, VSSTATUS64_UXL);
}
if ((env->henvcfg & HENVCFG_DTE)) {
if ((val & SSTATUS_SDT) != 0) {
+20
View File
@@ -609,13 +609,27 @@ static int chsc_sei_nt2_have_event(void)
#define CHSC_SEI_NT0 (1ULL << 63)
#define CHSC_SEI_NT2 (1ULL << 61)
#define CHSC_SEI_0_FMT 0x0f000000
static void ioinst_handle_chsc_sei(ChscReq *req, ChscResp *res)
{
uint64_t selection_mask = ldq_be_p(&req->param1);
uint32_t param0 = be32_to_cpu(req->param0);
uint8_t *res_flags = (uint8_t *)res->data;
uint16_t len = be16_to_cpu(req->len);
uint16_t resp_code;
int have_event = 0;
int have_more = 0;
if (len != 0x0010) {
resp_code = 0x0003;
goto out_err;
}
if (param0 & CHSC_SEI_0_FMT) {
resp_code = 0x0007;
goto out_err;
}
/* regarding architecture nt0 can not be masked */
have_event = !chsc_sei_nt0_get_event(res);
have_more = chsc_sei_nt0_have_event();
@@ -642,6 +656,12 @@ static void ioinst_handle_chsc_sei(ChscReq *req, ChscResp *res)
res->code = cpu_to_be16(0x0005);
res->len = cpu_to_be16(CHSC_MIN_RESP_LEN);
}
return;
out_err:
res->code = cpu_to_be16(resp_code);
res->len = cpu_to_be16(CHSC_MIN_RESP_LEN);
res->param = 0;
}
static void ioinst_handle_chsc_unimplemented(ChscResp *res)
+9
View File
@@ -1791,6 +1791,15 @@ static void insert_stsi_3_2_2(S390CPU *cpu, __u64 addr, uint8_t ar)
} else if (s390_cpu_virt_mem_read(cpu, addr, ar, &sysib, sizeof(sysib))) {
return;
}
/*
* The memory was filled by the kernel but mapped into the guest.
* If something is fishy, do not touch the buffer.
*/
if (sysib.count == 0 || sysib.count > ARRAY_SIZE(sysib.ext_names)) {
return;
}
/* Shift the stack of Extended Names to prepare for our own data */
memmove(&sysib.ext_names[1], &sysib.ext_names[0],
sizeof(sysib.ext_names[0]) * (sysib.count - 1));
+1 -1
View File
@@ -487,7 +487,7 @@ void helper_ftrv(CPUSH4State *env, uint32_t n)
float32 p;
bank_matrix = (env->sr & FPSCR_FR) ? 0 : 16;
bank_vector = (env->sr & FPSCR_FR) ? 16 : 0;
bank_vector = (env->sr & FPSCR_FR) ? 16 + n : n;
set_float_exception_flags(0, &env->fp_status);
for (i = 0 ; i < 4 ; i++) {
r[i] = float32_zero;
+5 -10
View File
@@ -377,11 +377,6 @@ static inline void gen_store_fpr64(DisasContext *ctx, TCGv_i64 t, int reg)
goto do_illegal; \
}
#define CHECK_FPSCR_PR_1 \
if (!(ctx->tbflags & FPSCR_PR)) { \
goto do_illegal; \
}
#define CHECK_SH4A \
if (!(ctx->features & SH_FEATURE_SH4A)) { \
goto do_illegal; \
@@ -1740,22 +1735,22 @@ static void _decode_opc(DisasContext * ctx)
return;
case 0xf0ed: /* fipr FVm,FVn */
CHECK_FPU_ENABLED
CHECK_FPSCR_PR_1
CHECK_FPSCR_PR_0
{
TCGv m = tcg_constant_i32((ctx->opcode >> 8) & 3);
TCGv n = tcg_constant_i32((ctx->opcode >> 10) & 3);
TCGv m = tcg_constant_i32(((ctx->opcode >> 8) & 3) << 2);
TCGv n = tcg_constant_i32(((ctx->opcode >> 10) & 3) << 2);
gen_helper_fipr(tcg_env, m, n);
return;
}
break;
case 0xf0fd: /* ftrv XMTRX,FVn */
CHECK_FPU_ENABLED
CHECK_FPSCR_PR_1
CHECK_FPSCR_PR_0
{
if ((ctx->opcode & 0x0300) != 0x0100) {
goto do_illegal;
}
TCGv n = tcg_constant_i32((ctx->opcode >> 10) & 3);
TCGv n = tcg_constant_i32(((ctx->opcode >> 10) & 3) << 2);
gen_helper_ftrv(tcg_env, n);
return;
}
Loaded 100 of 117 files, more files were not shown because too many files have changed in this diff. Show more