Commit Graph
635 Commits
Author SHA1 Message Date
Richard Henderson 8cb1f6929a Merge tag 'qtest-20261029-pull-request' of https://gitlab.com/farosas/qemu into staging
QTest pull request

- Lift limit of 256 intercepted IRQs
- Fixes to socket_accept

# -----BEGIN PGP SIGNATURE-----
#
# iQJEBAABCAAuFiEEqhtIsKIjJqWkw2TPx5jcdBvsMZ0FAmrjtQoQHGZhcm9zYXNA
# c3VzZS5kZQAKCRDHmNx0G+wxnUSOD/9LV7iBwq42IGxOiKnkjbLKAjHlBruYR4/e
# hkWgfIjNn/VGPj++ueNexNxu8QpYuzZxOXDedTFguCzJqz/HfbaeoZ4uQ9gSa1W0
# j4NqUFWfppi4XF02rvZelXsdi9FrVgOCmrBT/bpZNI0HQzU1dxXWOQXYbkMfsjXf
# Ax/vTH6DR02IBfk583JwxZMuPj63PfLOEwGnr3TBAsuKcQJMtgs8iR14z22xe1x7
# mJ6wLFXgTE4utx60JM1bSa3wZU8ADmRq7njtx6QaoM7x1VX70P6eNE8UeJbmxP6j
# U72DO/5+sZc5mITPQYWJ9mfJohJU+G2fB4263Yo2G0bqs7gF7B8Z3yY/JekYYyH/
# GCm3DuH49EqMMRAMgK8CoW83682kuFIt/9tmD4DATlPlcvlNPCP9d7rnckQH5Hti
# 37pPGMGYeQF4Bl1lYrxdUKUro6eOLemesl06lPjuYEsZHVmxSkZGZ7R2lh7MGYCD
# 4RjXOJa01guP6NeUBUi76JamhtpebaLAjsQXOF8EWA0kS30XG9J1+RRXEoQ8HRUr
# zhDZ32wpfylhmViCasFt9ib+0BOdiMbA86buDGmd1rx5yKCGJUStQF0pX/tkgB0P
# FV9U8AL7TobTqxWe3Q676tFykPE5KBHB7grc+L+GDo2JVBCF0CcPyyCdA8I5ar4N
# 4CpG1ZlhJw==
# =ZyWU
# -----END PGP SIGNATURE-----
# gpg: Signature made Thu 29 Oct 2026 04:05:14 PM CDT
# gpg:                using RSA key AA1B48B0A22326A5A4C364CFC798DC741BEC319D
# gpg:                issuer "farosas@suse.de"
# gpg: Good signature from "Fabiano Rosas <farosas@suse.de>" [unknown]
# gpg:                 aka "Fabiano Almeida Rosas <fabiano.rosas@suse.com>" [unknown]
# gpg: WARNING: The key's User ID is not certified with a trusted signature!
# gpg:          There is no indication that the signature belongs to the owner.
# Primary key fingerprint: AA1B 48B0 A223 26A5 A4C3  64CF C798 DC74 1BEC 319D

* tag 'qtest-20261029-pull-request' of https://gitlab.com/farosas/qemu:
  qtest: don't close listener socket in qtest_socket_accept
  qtest: multiple fixes to socket_accept()
  tests/qtest/libqtest: Use a GArray for QTestState::irq_level[]
  system/qtest: Check ngl->name for irq_intercept_in
  system/qtest: Avoid fixed-size irq_levels array for IRQ intercept

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
2026-10-29 17:08:44 -05:00
Peter Maydell e91bdf25f7 system/qtest: Check ngl->name for irq_intercept_in
Currently we check the name of the NamedGPIOList when doing
irq_intercept_out, but not for irq_intercept_in.  Even though we
don't currently support irq_intercept_in on named GPIO lines, we
still need to check the name, because otherwise we will install the
observer on every set of GPIO inputs the device has, rather than only
for the unnamed GPIO inputs.

This doesn't currently affect any test cases, because of all the
tests which use irq_intercept_in only tests/qtest-l2vic-test.c uses
it on a device that creates named GPIO inputs.  That device has both
unnamed GPIO inputs and a named GPIO input "reset".  The effect is
that a change in the "reset" line state looks like a change in
interrupt input line 0; but since the test doesn't cause "reset" to
change this doesn't happen and there are no observable effects of the
bug.

Check the ngl->name against the specified one for both input
and output interception. (Currently this will be equivalent to
a check against NULL for input intercepts.) As we're now checking
for an exact name match unconditionally, we can break out of the
loop as soon as we've found it.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Fabiano Rosas <farosas@suse.de>
Signed-off-by: Fabiano Rosas <farosas@suse.de>
2026-10-29 15:49:12 -03:00
Peter Maydell 7f34660a58 system/qtest: Avoid fixed-size irq_levels array for IRQ intercept
The current implementation of the irq_intercept_out and
irq_intercept_in commands uses a fixed-size static irq_levels[] array
to track the state of the intercepted IRQ lines.  This is sized at
MAX_IRQ == 256, which is smaller than some real device models use
(for instance the GICv2 on the virt board has 384 inputs).  A test
that tried to intercept the inputs to such a device and then assert
an interrupt over 255 would overrun the array.

Reimplement the IRQ interception so that it allocates an array
of the required size rather than using a static one.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Fabiano Rosas <farosas@suse.de>
Signed-off-by: Fabiano Rosas <farosas@suse.de>
2026-10-29 15:49:12 -03:00
Richard Henderson b574eaf640 Merge tag 'for_upstream' of https://git.kernel.org/pub/scm/virt/kvm/mst/qemu into staging
pci, vhost, virtio, iommu, acpi: features, fixes

multiboot can again load 64 bit images
vdpa-dev now implements guest_notifier_mask/pending
pci bridge can now configure the negotiated bandwidth
tap can now auto-detect host mtu and expose to guest
amd iommu can now attach on non system bus
vhost-user spec now has its own mailing list

Fixes, cleanups all over the place.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>

# -----BEGIN PGP SIGNATURE-----
#
# iQFDBAABCgAtFiEEXQn9CHHI+FuUyooNKB8NuNKNVGkFAmrjkJ0PHG1zdEByZWRo
# YXQuY29tAAoJECgfDbjSjVRpY1YH/0r+PhxgcRVVrroGkIxaTaPfOpTj1UkGPmND
# OcjcVCKPXBJF+rve1ZOE4HF8VvbEU1fD1tJ6w+Hto78tjmaVEDvE7gVbhX3YRHv9
# LubC75aTJBYixn/wcS/LUyLAf50+3DD3T+yy83obaJmxHwFyO3CJh2CIMSQxTbSe
# zGPA0noriSSMKEnfbTtikj6NHvFIhdnYipkUaWjGefEbdzXumBhcAF2C7eee9H5m
# 1Nz1Zvjx7BMoArviiZ6EWpGwWPBp0fKwTa7Idcv9K5v6YfWhgVp/gPploCCvulEA
# SMYRqQbbQ41801jR8kY9mV5w5ZFUeNENqplbOR3y6dYtr2w+H2k=
# =JvkM
# -----END PGP SIGNATURE-----
# gpg: Signature made Thu 29 Oct 2026 01:29:49 PM CDT
# gpg:                using RSA key 5D09FD0871C8F85B94CA8A0D281F0DB8D28D5469
# gpg:                issuer "mst@redhat.com"
# gpg: Good signature from "Michael S. Tsirkin <mst@kernel.org>" [unknown]
# gpg:                 aka "Michael S. Tsirkin <mst@redhat.com>" [unknown]
# gpg: WARNING: The key's User ID is not certified with a trusted signature!
# gpg:          There is no indication that the signature belongs to the owner.
# Primary key fingerprint: 0270 606B 6F3C DF3D 0B17  0970 C350 3912 AFBE 8E67
#      Subkey fingerprint: 5D09 FD08 71C8 F85B 94CA  8A0D 281F 0DB8 D28D 5469

* tag 'for_upstream' of https://git.kernel.org/pub/scm/virt/kvm/mst/qemu: (77 commits)
  virtio-net: add mtu-from-tap property for automatic MTU detection
  net: add generic get_mtu NetClientInfo callback
  net/tap: add tap_fd_get_mtu() to query host tap MTU
  hw/virtio/virtio-mem: Fix error message on invalid NUMA node
  intel_iommu_accel: Teardown FAULTQ resources in bottom half
  intel_iommu_accel: Accept PRQ response for passthrough device
  intel_iommu_accel: Add PRQ injection for passthrough device
  backends/iommufd: Extend iommufd_backend_alloc_hwpt() with fault_id
  backends/iommufd: Introduce iommufd_backend_alloc_faultq
  intel_iommu_accel: Guard VTDAccelPASIDCacheEntry definition
  amd_iommu: Allow IOMMU to attachment on non-system (pcie.0) bus
  acpi-build: Create PCI topology using amd iommu root bus
  amd_iommu: Introduce root bus
  i386/kvm: Use x86_iommu_device_get() for per-device IOMMU lookup
  intel_iommu: Add support for get_x86_iommu callback
  amd_iommu: Add support for get_x86_iommu callback
  x86-iommu: Introduce x86_iommu_device_get() for x86-iommu retrieval
  amd_iommu: Assign ioapic_as only when interrupt remapping is supported.
  vhost-user: add dedicated mailing list
  virtio-snd: don't use virtio_snd_pcm_get_stream() in virtio_snd_post_load()
  ...

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
2026-10-29 13:47:40 -05:00
Andrey Drobyshev de80025348 migration/cpr: forbid saving duplicate CprFds into hash table
In its current form, the mechanism for saving CPR FDs into hash table
has flaws.

The CPR fd hash table uses the same CprFd for both key and value, and
is created with a key destroy function.  Inserting a second element
with the same (name, id) key leads to a use after free.  According to
GLib docs [1], g_hash_table_insert() keeps the old key, replaces the
value with the new element, and destroys the new key.  Thus when
inserting 2 CprFd elements fd1 and fd2 with equal keys we get:

  g_hash_table_insert(table, fd1, fd1);  /* table has fd1 -> fd1 */
  g_hash_table_insert(table, fd2, fd2);  /* table has fd1 -> fd2, fd2 freed */

Any subsequent cpr_find_fd() for that key then returns freed memory.

This is reachable whenever two CPR-aware objects register fds under the
same name, and it happens long before an actual CPR, since cpr_save_fd()
is typically called from .realize(), i.e. at boot time.

Apart from the UAF itself, when the user decides to perform CPR migration,
on CPR target we'd get corrupted FD from the hash table and fail somewhere
in .realize() for affected devices.

As a solution, let's altogether prohibit adding CprFds with duplicate
keys.  Since FDs are being registered for a subsequent CPR right at the
startup in .realize(), that'll allow us to error out and exit QEMU (or
fail a device hotplug op) gracefully instead of delaying potential
problems for later.  To do so, let's make cpr_save_fd() return 'bool'
instead of 'void' and provide an 'errp' argument to it.  That way caller
becomes responsible for checking the return value and propagating the
error.

Also update all the callers to use the adjusted interface to keep things
compilable and bisectable.

[1] https://docs.gtk.org/glib/type_func.HashTable.insert.html

Fixes: a181df93bb ("migration/cpr: use hashtable for cpr fds")
Reviewed-by: Peter Xu <peterx@redhat.com>
Reviewed-by: Cédric Le Goater <clg@redhat.com>
Signed-off-by: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Message-ID: <20261012-up-vsock-vhost-v5-v16-1-36c38bd15ffc@virtuozzo.com>
2026-10-29 14:26:56 -04:00
Yonggang Luo 8930d9cca2 qemu/arch-defs: increase width of QEMU_ARCH_* masks enums to be 64 bits
SYS_EMU_TARGET__MAX is already 29, nearing the 32-target limit.
So increase width of QEMU_ARCH_* masks enums and related types;
So that we can add needed Linux user-mode targets to EmuTarget;
And also enabled the possibility add more system-mode targets in future.

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Reviewed-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>
Message-ID: <20261027061504.2213-4-luoyonggang@gmail.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
2026-10-28 09:25:48 +01:00
Daniel P. Berrangé e9f2ecafb1 seccomp: drop redundant match for clone() flags == 0
We have seccomp matches for clone() which mandate the presence of
several flags, in order to permit pthreads_create:

  REQUIRE_CLONE_FLAG(CLONE_VM);
  REQUIRE_CLONE_FLAG(CLONE_FS);
  ...

Given those mandatory matches, it is impossible for flags == 0 to
pass the filter. This is fortunate, since the explicit match on
flags == 0 is in fact broken, as it has a silent size extension
from 32-bits to 64-bits.

This results in seccomp generating pseudo code of:

    if ($arch == 3221225534)
      # filter for syscall "clone" (56) [priority: 65531]
      if ($syscall == 56)
        if ($a0.hi32 & 0xffffffff == 0)
          if ($a0.lo32 & 0xffffff00 == 0)
            action ERRNO(1);
      # default action
      action ALLOW;
    # invalid architecture action
    action KILL;

Since the clone() flag is passed as a 32-bit value in the syscall,
the high 32-bits are liable to be undefined/uninitialized garbage

The desired match for flags == 0 was

    if ($arch == 3221225534)
      # filter for syscall "clone" (56) [priority: 65532]
      if ($syscall == 56)
        if ($a0.hi32 & 0x00000000 == 0)
          if ($a0.lo32 & 0xffffff00 == 0)
            action ERRNO(1);
      # default action
      action ALLOW;
    # invalid architecture action
    action KILL;

That is redundant, however, as can be seen if we look at the
(fixed) program with the CLONE_THREAD rule also present:

    if ($arch == 3221225534)
      # filter for syscall "clone" (56) [priority: 65532]
      if ($syscall == 56)
        if ($a0.hi32 & 0x00000000 == 0)
          if ($a0.lo32 & 0xffffff00 == 0)
            action ERRNO(1);
          if ($a0.lo32 & 0x00010000 == 0)
            action ERRNO(1);
      # default action
      action ALLOW;
    # invalid architecture action
    action KILL;

That "($a0.lo32 & 0x00010000 == 0)" match will catch the case
of flags == 0 and do the right thing.

Reported-by: Ricardo Branco (https://gitlab.com/ricardobranco777)
Related: https://gitlab.com/qemu-project/qemu/-/work_items/4671
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2026-10-15 13:03:41 +01:00
Daniel P. Berrangé a567ef8655 seccomp: really fix blocking of setns/execveat/unshare
The previous fix for setns/execveat/unshare mistakenly copy and
pasted the clone_args filter, which is inappropriate for these
syscalls and had the effect of weakening the seccomp filter.

Fixes: f33fb19cab (seccomp: fix blocking of setns/execveat/unshare)
Fixes: https://gitlab.com/qemu-project/qemu/-/work_items/4671
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2026-10-15 13:03:41 +01:00
Richard Henderson 615ece3c40 Merge tag 'for-upstream' of https://gitlab.com/bonzini/qemu into staging
* target/i386/tcg: fix EFLAGS reads in TCG plugin callbacks
* target/i386/tcg: raise #GP(0) on null SS load with RPL != CPL
* target/i386/tcg: Don't clear C1 for FCOMI/FCOMIP/FUCOMI/FUCOMIP
* target/i386/tcg: implement APX
* target/i386: Migrate error code only with an exception
* agents: Add a skill for finding your way around QEMU
* tdx: fix buffer overflow in tdx_parse_panic_message
* accel/kvm: fixes

# -----BEGIN PGP SIGNATURE-----
#
# iQFIBAABCgAyFiEE8TM4V0tmI4mGbHaCv/vSX3jHroMFAmrDtEEUHHBib256aW5p
# QHJlZGhhdC5jb20ACgkQv/vSX3jHroN54Qf/WWX2G/Jh3WsKI7/9ahX+aqaOsGqP
# hdz8c6VurrGFwD4a6W8M73962XvrSlR0cNixXxjEo5lZ5UEuLXoCNuNHOW7TTHgF
# tGbfmX8hDMsU/VepRXjIVq5CQuJx6GJtYGf0bWROt3FkM3mn9xYevKu6bg9szNEX
# 3P71MtHIH/CMqP6/oI6VdHeGmNhGamiAoSLqly5t303CbtCULZiTZlqf3xMxjvVO
# M+hFMaW44kvXmpKWo8XLkWhcEasBuULJdKgq7cRIIrE1VNM+f9tItaEbxmozxlfT
# ae5+y1M/H5LAwjYLqTgUy2mvCcZ/btcdjU+wrWzYeSuAcOu4IRC1jQ4ozw==
# =d5mw
# -----END PGP SIGNATURE-----
# gpg: Signature made Mon 05 Oct 2026 04:29:21 PM CEST
# gpg:                using RSA key F13338574B662389866C7682BFFBD25F78C7AE83
# gpg:                issuer "pbonzini@redhat.com"
# gpg: Good signature from "Paolo Bonzini <bonzini@gnu.org>" [unknown]
# gpg:                 aka "Paolo Bonzini <pbonzini@redhat.com>" [unknown]
# gpg: WARNING: The key's User ID is not certified with a trusted signature!
# gpg:          There is no indication that the signature belongs to the owner.
# Primary key fingerprint: 46F5 9FBD 57D6 12E7 BFD4  E2F7 7E15 100C CD36 69B1
#      Subkey fingerprint: F133 3857 4B66 2389 866C  7682 BFFB D25F 78C7 AE83

* tag 'for-upstream' of https://gitlab.com/bonzini/qemu: (32 commits)
  agents: Add a skill for finding your way around QEMU
  target/i386/tcg: mark APX as supported
  target/i386: extract computation of no-autoenable features
  target/i386/tcg: optimize CCMP
  target/i386/tcg: decode APX instructions
  target/i386/tcg: implement CCMP/CTEST
  target/i386/tcg: add decode functionality for APX
  target/i386/tcg: decode EVEX prefix
  target/i386/tcg: extend VEX.vvvv parsing for APX
  target/i386/tcg: implement JMPABS instruction
  target/i386/tcg: decode REX2 prefix
  target/i386/tcg: treat 0x0F as a prefix
  target/i386/tcg: mark XSAVE* as not allowing REX2
  target/i386/tcg: add definition for REX2 prefix
  target/i386/tcg: add APX support to XSAVE/XRSTOR
  target/i386/tcg: unify MOVBE and BSWAP generators
  target/i386/tcg: use zextT1 for CMPXCHG
  target/i386/tcg: use standard operand order for BSF and BSR
  target/i386/tcg: generalize zero- and sign-extension
  accel/kvm: coalesced mmio: check lenght of the MMIO write entry
  ...

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
2026-10-09 15:49:53 +02:00
Richard Henderson 339eae3403 Merge tag 'misc-fixes-pull-request' of https://gitlab.com/berrange/qemu into staging
Merge USB, I/O and seccomp fixes

* Fix seccomp to use errno action for setns/execveat/unshare
  instead of killing the thread
* Improve TLS performance and avoid test suite timeouts by
  corking TLS writes to increase packet size
* Fix websocket server unbounded read of client data
  CVE-2026-101291
* Avoid use-after-free in MTP device during object delete

# -----BEGIN PGP SIGNATURE-----
#
# iQIzBAABCAAdFiEEOSEivHoFu8YQee2OpU5XPKwd8GwFAmrEslEACgkQpU5XPKwd
# 8GzKxA//fWvTM+u6OVK3vC2ieh87B9EHLMIxQ86jyCW9CReoX/8GQBrGpoWOW3oy
# 7P2TsLTS6HvxKWITcuAAdXR0iWZheOUcj8vcEozSMJuZ4ozQKpC1TPV+ViXv2bfB
# CASqTs/G+MaJETsiAM2Q4p8Glwh9MV55GnYwzAkvrCM+y7Jpl6PgxzcFFkVxw5DC
# drCuuNXKUKwf/eoCzcIWtYTicMb/5OA6Bs3NwDQSKCyAwBWyRWti4pzGftfZzNvd
# 1Dyy4fD0mQUO637EsnNu/k53s0Eu7Mt5UxQSU+hCJVMgOjZfcTdDV6wAXGVkNPN+
# jlBSJ2Jj38CJ3bgk6o7XJvFJgbZycRynC60LCLrW5O2X9acOQcgYY1XSpqC9l+QG
# WlK72oK3XI+mqubdBrUFMntEJr8JMD9dNN+eG7Zs33spQcmjmfBYDRX2lpe+HIfP
# ePpQA6pe5hKjhKeqXPZJhjvRSUwA7lHbfLs0NYblRLNGe1O3zvsX89M4xQ9G/f0x
# 5uAOdGi4IWfkNlgfHZRdSVI0t/UWHevyTvTNXSNPkLgFRAD9d4TRt3d/6WvXOZgr
# miFWbwWpdNVwbpEI9gIvPYns6skDy1doypLsF7TQz4byPpwl5BROdED/M1fGnLyA
# Ie+pXhEjk2Ah8/kmJTiyxZVLvx9K/itOJNca439IJZSIwMAhLf0=
# =VJrG
# -----END PGP SIGNATURE-----
# gpg: Signature made Tue 06 Oct 2026 10:33:21 AM CEST
# gpg:                using RSA key 392122BC7A05BBC61079ED8EA54E573CAC1DF06C
# gpg: Good signature from "Daniel P. Berrange <dan@berrange.com>" [unknown]
# gpg:                 aka "Daniel P. Berrange <berrange@redhat.com>" [unknown]
# gpg: WARNING: This key is not certified with a trusted signature!
# gpg:          There is no indication that the signature belongs to the owner.
# Primary key fingerprint: DAF3 A6FD B26B 6291 2D0E  8E3F BE86 EBB4 1510 4FDF
#      Subkey fingerprint: 3921 22BC 7A05 BBC6 1079  ED8E A54E 573C AC1D F06C

* tag 'misc-fixes-pull-request' of https://gitlab.com/berrange/qemu:
  seccomp: fix blocking of setns/execveat/unshare
  io: cork TLS writes to avoid small TLS records
  io: prevent unbounded read of websocket data from client
  hw/usb: Fix USB MTP Use-After-Free in usb_mtp_deletefn List Iteration

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
2026-10-09 06:58:26 +02:00
Daniel P. Berrangé f33fb19cab seccomp: fix blocking of setns/execveat/unshare
The initializer for these syscalls missed the seccomp action
field, so it got the default action which was to kill the calling
thread, instead of returning an errno value, which the other
equivalent syscalls use.

Since we don't ever intend to use a seccomp filter without a
defined action, use an assert to validate that action is always
set to non-zero.

Reported-by: Igor Santos-Grueiro (gitlab:@igorsantosgrueiro)
Fixes: https://gitlab.com/qemu-project/qemu/-/work_items/4600
Fixes: 4638057110 (seccomp: block setns, unshare and execveat syscalls)
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2026-10-06 09:17:43 +01:00
Pierrick Bouvier a16372abe2 system/meson: use stub_ss for dtb stubs
Remove multiple definition of `qmp_dumpdtb' error, when linking m68k
target with other multi targets.

Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Link: https://lore.kernel.org/qemu-devel/20260930020108.217892-4-pierrick.bouvier@oss.qualcomm.com
Signed-off-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>
2026-10-05 11:54:09 -07:00
Maxim Levitsky b7f51182c0 system: fix buffer overflow in tdx_parse_panic_message
tdx_parse_panic_message has code that detects if the guest supplied
message contains some unprintable characters and in this case prints a hex dump.

The code has a bug: it allocates 3 bytes for 'sprintf("%02x ")',
but sprintf in this case actually writes at least 4 bytes, because it adds the NULL
terminator, or even 9 bytes if the char type is signed and the MSB is set.

To fix this, just use qemu_hexdump_line instead.

Reported-by: Jordy Zomer <jordyzomer@google.com>
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3905
Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
Link: https://lore.kernel.org/r/20260923004553.100732-1-mlevitsk@redhat.com
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2026-10-05 11:46:52 +02:00
Peter Xu 20879f0b41 memory: Rename memory_region_init_ram_guest_memfd() to *_private()
Differentiate it from fully shared guest-memfd use cases.

Suggested-by: Xiaoyao Li <xiaoyao.li@intel.com>
Reviewed-by: Xiaoyao Li <xiaoyao.li@intel.com>
Reviewed-by: Michael Roth <michael.roth@amd.com>
Reviewed-by: David Hildenbrand <david@kernel.org>
Signed-off-by: Michael Roth <michael.roth@amd.com>
Link: https://lore.kernel.org/r/20260929235109.1398509-10-michael.roth@amd.com
Signed-off-by: Peter Xu <peterx@redhat.com>
2026-09-30 08:51:04 -04:00
Peter Xu 9ee41317ad memory: Rename memory_region_has_guest_memfd() to *_private()
Rename the function with "_private" suffix, to show that it returns true
only if it has an internal guest-memfd to back private pages (rather than
fully shared guest-memfd).

Reviewed-by: Xiaoyao Li <xiaoyao.li@intel.com>
Reviewed-by: Michael Roth <michael.roth@amd.com>
Reviewed-by: David Hildenbrand <david@kernel.org>
Signed-off-by: Michael Roth <michael.roth@amd.com>
Link: https://lore.kernel.org/r/20260929235109.1398509-7-michael.roth@amd.com
Signed-off-by: Peter Xu <peterx@redhat.com>
2026-09-30 08:51:04 -04:00
Peter Xu 391bddff1f memory: Rename RAM_GUEST_MEMFD to RAM_GUEST_MEMFD_PRIVATE
This name is too generic, and can conflict with support for using
guest-memfd for shared memory. Add a _PRIVATE suffix to show what it
really means: it is using guest_memfd specifically for private memory;
whether or not guest_memfd is being used for shared memory is something
to be configured/determined separately.

This also paves way for in-place guest-memfd, which means we can have a
ramblock that allocates pages completely from guest-memfd (private or
shared).

Reviewed-by: Xiaoyao Li <xiaoyao.li@intel.com>
Reviewed-by: Michael Roth <michael.roth@amd.com>
Reviewed-by: David Hildenbrand <david@kernel.org>
Signed-off-by: Michael Roth <michael.roth@amd.com>
Link: https://lore.kernel.org/r/20260929235109.1398509-6-michael.roth@amd.com
Signed-off-by: Peter Xu <peterx@redhat.com>
2026-09-30 08:51:04 -04:00
Peter Xu dbdd685be9 ramblock: Rename guest_memfd to guest_memfd_private
Rename the field to reflect the fact that the guest_memfd in this case only
backs private portion of the ramblock rather than all of it.

Reviewed-by: Xiaoyao Li <xiaoyao.li@intel.com>
Reviewed-by: Michael Roth <michael.roth@amd.com>
Reviewed-by: David Hildenbrand <david@kernel.org>
Signed-off-by: Michael Roth <michael.roth@amd.com>
Link: https://lore.kernel.org/r/20260929235109.1398509-5-michael.roth@amd.com
Signed-off-by: Peter Xu <peterx@redhat.com>
2026-09-30 08:51:04 -04:00
Xiaoyao Li 26241579ef kvm: Decouple memory attribute check from kvm_guest_memfd_supported
With the mmap support of guest memfd, KVM allows userspace to create
guest memfd serving as normal non-private memory for X86 DEFAULT VM.
However, KVM doesn't support private memory attribute for X86 DEFAULT
VM.

Make kvm_guest_memfd_supported not rely on KVM_MEMORY_ATTRIBUTE_PRIVATE
and check KVM_MEMORY_ATTRIBUTE_PRIVATE separately when the machine
requires guest_memfd to serve as private memory.

This allows QEMU to create guest memfd with mmap to serve as the memory
backend for X86 DEFAULT VM.

Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com>
Reviewed-by: Fabiano Rosas <farosas@suse.de>
Reviewed-by: Michael Roth <michael.roth@amd.com>
Reviewed-by: David Hildenbrand <david@kernel.org>
Signed-off-by: Michael Roth <michael.roth@amd.com>
Link: https://lore.kernel.org/r/20260929235109.1398509-2-michael.roth@amd.com
Signed-off-by: Peter Xu <peterx@redhat.com>
2026-09-30 08:51:04 -04:00
Matt Turner d06c6a1303 accel/tcg: fold the dynamic cflags into CPUState::tcg_cflags
curr_cflags() is called once per TB dispatch, from helper_lookup_tb_ptr()
and from the cpu_exec() loop. It recomputes the same value every time:

    uint32_t cflags = cpu->tcg_cflags;
    if (unlikely(cpu_single_stepping(cpu))) { ... }
    else if (qatomic_read(&one_insn_per_tb)) { ... }
    else if (qemu_loglevel_mask(CPU_LOG_TB_NOCHAIN)) { ... }

That is three loads and three branches on the hottest path in the
interpreter, for state that changes only when gdb enables single-step,
when one-insn-per-tb is toggled, or when the log mask changes.

None of the three has to be sampled at dispatch time. Fold each into
CPUState::tcg_cflags where it changes and curr_cflags() becomes a single
load of a field that TB lookup has to read anyway.

The derived bits -- CF_COUNT_MASK, CF_NO_GOTO_TB, CF_NO_GOTO_PTR and
CF_SINGLE_STEP -- are never set by tcg_cflags_set(), so tcg_update_cflags()
can recompute them in place without disturbing the rest, and conversely
tcg_cflags_set() ORs in its bits without disturbing them.

There are three places to call it:

  - tcg_exec_realizefn(), so that a CPU created after the command line has
    been parsed starts out with the right value. This covers user-only,
    where tcg_cpu_init_cflags() is not reached. linux-user's cpu_copy()
    copies tcg_cflags wholesale, so a cloned thread inherits it.

  - cpu_single_step(), which changes one CPU.  gdb is the only caller that
    matters; in system mode it runs with the vCPUs stopped, and in user mode
    gdb_continue_partial() can reach a thread that is still running, because
    gdb_handlesig() stops only the thread that trapped. That is exactly the
    plain cross-thread store to another CPU's CPUState that
    cpu->singlestep_flags already was, read back by that CPU through
    cpu_single_stepping() in curr_cflags(). This patch changes which field
    carries it, not who writes it or how.

  - hmp_one_insn_per_tb() and hmp_log(), which change every CPU while the
    vCPUs are running, so the update is queued with async_run_on_cpu() and
    each CPU writes its own cflags from its own thread. The command line
    spellings of those two settings need nothing: they are parsed before
    any CPU is realized, so tcg_exec_realizefn() picks them up.

Measured with qemu-alpha running an emulated alpha gcc 16.2.0 compiling
the SQLite 3.45.1 amalgamation (255k lines, -O2) on an x86-64 host, in a
build configured with --enable-lto:

    before: 1,646,994,254,249 instructions
    after:  1,562,204,796,597 instructions   -5.15%

That workload issues 8.4 billion dispatches, so the per-call saving is
small but the aggregate is not. The emulated compiler produces
byte-identical output before and after.

Wall clock does not move: 133.19s to 132.58s, a 0.46% difference against a
run-to-run spread larger than that. The removed work is a few predictable
loads and branches that the host executes largely in parallel with the
surrounding dispatch, so this patch is worth taking for the instruction
count and for what it enables, not for a time saving that can be measured
on its own.

v4: Update the cflags from the HMP handlers for 'log' and 'one-insn-per-tb'
    rather than from qemu_set_log_internal() and the accelerator property
    setter. Those are the paths that reach a running vCPU, and the monitor
    is the only thing that does. Suggested by Richard Henderson.

v4: Queue the per-CPU update with async_run_on_cpu() rather than
    async_safe_run_on_cpu(). Halting the other vCPUs buys nothing: the
    queued work already runs on the owning CPU's own thread. Suggested by
    Alex Bennee, who also asked whether there are cross-vCPU updates of
    tcg_cflags at all. With this change the monitor path has none: the
    only remaining writer from another thread is cpu_single_step(), above,
    which is neither new nor made worse here.

v4: Move the stub to accel/stubs/, which is where the other accelerator
    stubs live.

Signed-off-by: Matt Turner <mattst88@gmail.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Message-ID: <20260901034808.3524945-2-mattst88@gmail.com>
2026-09-23 15:10:08 -07:00
Richard Henderson f348612449 Merge tag 'next-pull-request' of https://gitlab.com/peterx/qemu into staging
Mem api pull

- Peter's patchset to drop some dead code for 32bit hosts
- Phil/Bin's patch to enhance error message for mem allocations
- Cam's fix to virtio-mem crash in multi-source work

# -----BEGIN PGP SIGNATURE-----
#
# iIgEABYKADAWIQS5GE3CDMRX2s990ak7X8zN86vXBgUCaq0ivhIccGV0ZXJ4QHJl
# ZGhhdC5jb20ACgkQO1/MzfOr1wbtGQD/djQyYM2zWEh5SyDDhbT4cj7iPIkvFtCM
# MVQNJPFkZLUBANMM8sWaoEaIsehh+tLq+6zvqyAB5U9yF8ecuYgR6iEH
# =n5bF
# -----END PGP SIGNATURE-----
# gpg: Signature made Fri 18 Sep 2026 01:38:38 AM HST
# gpg:                using EDDSA key B9184DC20CC457DACF7DD1A93B5FCCCDF3ABD706
# gpg:                issuer "peterx@redhat.com"
# gpg: Good signature from "Peter Xu <xzpeter@gmail.com>" [unknown]
# gpg:                 aka "Peter Xu <peterx@redhat.com>" [unknown]
# gpg: WARNING: The key's User ID is not certified with a trusted signature!
# gpg:          There is no indication that the signature belongs to the owner.
# Primary key fingerprint: B918 4DC2 0CC4 57DA CF7D  D1A9 3B5F CCCD F3AB D706

* tag 'next-pull-request' of https://gitlab.com/peterx/qemu:
  system/ram-discard-manager: fix offset_within_address_space in replay_by_populated_state()
  system/physmem: Improve guest memory allocation failure error message
  machine: Remove 32bit limitation on ram size
  hw/arm/raspi4b: Drop board_rev for 32bit hosts
  arm/aspeed: Drop ASPEED_RAM_SIZE
  linux-user: Remove 32bit host support in thunk_convert|print()
  bsd-user: Remove 32bit host support in thunk_convert|print()
  xen-mapcache: Remove 32bit support
  arm/mps: Remove 32bit define for MPS3_DDR_SIZE
  hw/vexpress.c: Remove forced cast to u64
  system: Define ram_addr_t to be always uint64_t

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
2026-09-18 09:23:04 -10:00
Cam Miller 666dd3c9b1 system/ram-discard-manager: fix offset_within_address_space in replay_by_populated_state()
Fix bug inside replay_by_populated_state() that forgets to initialize
MemoryRegionSection field offset_within_address_space. Follow the
established pattern of calling memory_region_section_intersect_range()
to accomplish this task.

Prior to commit cc9c77f4dd ("system/memory: implement
RamDiscardManager multi-source aggregation"),
replay_by_populated_state() had called
memory_region_section_intersect_range() in order to initialize
interdependent fields offset_within_address_space, offset_within_region,
and size together, as shown below.

    s->offset_within_address_space += start - s->offset_within_region;
    s->offset_within_region = start;
    s->size = int128_sub(end, int128_make64(start));

cc9c77f4dd reimplements replay_by_populated_state() initializing the
fields of the given MemoryRegionSection instance by hand instead of via
memory_region_section_intersect_range(). In doing so, it leaves
offset_within_address_space uninitialized for some reason, as you can
see below.

    MemoryRegionSection subsection = {
        .mr = section->mr,
        .offset_within_region = offset,
        .size = int128_make64(MIN(granularity, end_offset - offset)),
    };

Consequently offset_within_address_space defaults to GPA 0x0, which is
incorrect. For example, on s390x, base RAM begins at GPA 0x0 and it is
problematic to report that a virtio-iommu MR section lives there
instead.

cc9c77f4dd deliberately calls memory_region_section_intersect_range()
from other related code paths inside the same file, namely
replay_source_by_state() and rdl_populate_cb()/rdl_discard_cb(). It is
unclear why the new replay_by_populated_state() implementation does not
conform to this same pattern.

The effects of the bug include qemu crashes on multiple architectures.
The following assertion failure occurs when driving the
guest_phys_blocks_append() code path, for guests with virtio-mem device
that has some memory plugged.

    DBG: guest_phys_block_add_section: predecessor->target_end=280000000 target_start=0
    **
    ERROR:../system/memory_mapping.c:222:guest_phys_block_add_section: assertion failed: (predecessor->target_end <= target_start)
    Bail out! ERROR:../system/memory_mapping.c:222:guest_phys_block_add_section: assertion failed: (predecessor->target_end <= target_start)
    2026-09-11 16:03:57.405+0000: shutting down, reason=crashed

This crash can be triggered on x86 via the dump-guest-memory QMP
command. The same crash can be triggered on s390x by restoring VM State
that has been migrated to a local file. (I used libvirt to manage this
migration restore operation, namely command virsh managedsave then virsh
start.) Applying the fix resolved the crash on both platforms.

Cc: qemu-stable <qemu-stable@nongnu.org>
Fixes: cc9c77f4dd ("system/memory: implement RamDiscardManager multi-source aggregation")
Reported-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
Signed-off-by: Cam Miller <cam@linux.ibm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Link: https://lore.kernel.org/r/20260914-vmem_fix-v1-1-f69ef04a07b0@linux.ibm.com
Signed-off-by: Peter Xu <peterx@redhat.com>
2026-09-18 07:36:52 -04:00
Philippe Mathieu-Daudé 9224a0666b system/physmem: Improve guest memory allocation failure error message
When Linux refuses to overcommit a seriously wild allocation we get:

  $ qemu-system-i386 -m 40000000
  qemu-system-i386: cannot set up guest memory 'pc.ram':
  Cannot allocate memory

Slightly improve the error message, displaying the memory size
requested (in case the user didn't expect unspecified memory size
unit is in MiB):

  $ qemu-system-i386 -m 40000000
  qemu-system-i386: Cannot set up 38.1 TiB of guest memory 'pc.ram':
  Cannot allocate memory

Reported-by: Bin Meng <bmeng.cn@gmail.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Peter Xu <peterx@redhat.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>
Signed-off-by: Bin Meng <bin.meng@processmission.com>
Link: https://lore.kernel.org/r/20260822122710.3731595-2-bin.meng@processmission.com
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Peter Xu <peterx@redhat.com>
Cc: "Philippe Mathieu-Daudé" <philmd@mailo.com>
Signed-off-by: Peter Xu <peterx@redhat.com>
2026-09-18 07:36:52 -04:00
Daniel P. Berrangé 05e933ac25 system: report device security status in help output
When '-device help', 'device_add help' and 'info qdm' are used, report
the security status of each device.

Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2026-09-17 17:00:44 +01:00
Daniel P. Berrangé 0618402fff system: check security of device types
This wires up the DeviceClass types to have their
security checked when devices are created.

Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2026-09-17 17:00:44 +01:00
Daniel P. Berrangé 3fa876d489 system: report machine security status in help output
When '-machine help' is given, report the security status of each
machine.

Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2026-09-17 17:00:44 +01:00
Daniel P. Berrangé cdf00fb2f6 system: check security for machine types
This wires up the machine creation code to apply the compat policy
security check.

Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2026-09-17 17:00:44 +01:00
Daniel P. Berrangé d3b770fc63 system: report acclerator security status in help output
When '-accel help' is given, report the security status of each
accelerator.

Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2026-09-17 17:00:44 +01:00
Daniel P. Berrangé 8bcd34c40e system: check security for accelerator types
This wires up the accelerator creation code to apply the compat policy
security check. When multiple -accel options are given, normal fallback
logic applies. IOW, if one is rejected by the security check, it will
carry on to try the next accelerator until one passes the security
check.

Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2026-09-17 17:00:44 +01:00
Philippe Mathieu-Daudé a64d024e04 hw/hotplug: Constify HotplugHandler
HotplugHandler value returned from qdev_get_hotplug_handler()
points to the handler of and object implementing the
TYPE_HOTPLUG_HANDLER interface. That handler mostly points to
read-only section which shouldn't not be updated. Better
protect it with the const qualifier.

Mechanical change using 'sed' then manually adapted coding style.

Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Message-ID: <20260903230245.65601-5-philmd@oss.qualcomm.com>
2026-09-11 15:54:47 -04:00
Philippe Mathieu-Daudé fe15846519 hw/hotplug: Mark various HotplugHandlerClass variables as const
The HotplugHandlerClass pointers are only dereferenced, not updated.

Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Message-ID: <20260903230245.65601-3-philmd@oss.qualcomm.com>
2026-09-11 15:54:47 -04:00
Marc-André Lureau 554a1f83c6 memory: use object_property_add_link for container property
Replace the hand-rolled container property with
object_property_add_link().

With check=NULL the link has no setter (read-only), matching the
existing behaviour. The built-in link getter and resolver are
functionally identical to the removed memory_region_get_container() and
memory_region_resolve_container(). The non-STRONG flag avoids refcount
interference: mr->container is managed externally by
memory_region_add/del_subregion().

Reviewed-by: Peter Xu <peterx@redhat.com>
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2026-09-08 19:06:36 +04:00
Marc-André Lureau 98ce1fe5c0 system/memory: fix "priority" property typename
The value and the getter are int32.

Fixes: d33382da9a ("memory: MemoryRegion: Add may-overlap and priority props")
Reviewed-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2026-09-08 19:06:36 +04:00
Daniel P. Berrangé 562b2fe797 system: improve -mon deprecation warning
Expand the text a bit to make the new syntax more explicit and point
users to the man page for further info.

Reported-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Message-ID: <20260902104753.1756783-1-berrange@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
2026-09-03 12:22:32 +02:00
Pierrick Bouvier 6353016116 system: query machines using TYPE_MACHINE
We drop the target_machine_typename() we introduced previously, and
revert to using TYPE_MACHINE. From there, we'll make sure only the right
types are registered at startup time.

Signed-off-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Message-ID: <20260901202043.26532-4-pierrick.bouvier@oss.qualcomm.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
2026-09-03 12:22:32 +02:00
Philippe Mathieu-Daudé f54f88b6d2 system/cpus: Constify various CPUState arguments
Mark the CPUState structure const when it is only accessed read-only.

Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20260901095229.72018-6-philmd@oss.qualcomm.com>
2026-09-03 12:14:08 +02:00
Marc-André Lureau 34c5de5c6d build-sys: make HMP source files conditional on have_hmp
Exclude all *-hmp-cmds.c files and HMP-only source files from the
build when HMP is disabled.

Also conditionalise the hmp-commands.hx header generation and the
test-hmp qtest.

Acked-by: Dr. David Alan Gilbert <dave@treblig.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-ID: <20260828-qemu-no-hmp-v5-45-9227de146347@redhat.com>
2026-08-29 12:07:45 +04:00
Marc-André Lureau 0bd6562fc3 Guard HMP command implementations with CONFIG_HMP
Add #ifdef CONFIG_HMP around all hmp_* function implementations and
their HMP-only helpers across subsystems.

This covers monitor_register_hmp* callers, hmp_info_* handlers, and
HMP-only helper functions like slirp_lookup.

To link succesfully, use empty cmds tables in hmp-cmds.c (to be removed
once meson build-sys is updated with !hmp support later in the series)

Reviewed-by: Jason J. Herne <jjherne@linux.ibm.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-ID: <20260828-qemu-no-hmp-v5-41-9227de146347@redhat.com>
2026-08-29 12:07:45 +04:00
Marc-André Lureau b3b845f762 qdev-monitor: make print_dev() callback take MonitorHMP
The callback is specific to HMP context, avoid unsafe MONITOR_HMP()
cast.

Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-ID: <20260828-qemu-no-hmp-v5-39-9227de146347@redhat.com>
2026-08-29 12:07:45 +04:00
Marc-André Lureau f3900cfb0c monitor: tighten monitor_printf*()
Rename monitor_printf->monitor_hmp_printf, monitor_vprintf->
monitor_hmp_vprintf, and monitor_printc->monitor_hmp_printc, changing
the first parameter from Monitor * to MonitorHMP * to enforce type
safety. The implementation is also simplified: monitor_hmp_vprintf now
directly calls g_strdup_vprintf + monitor_puts, removing the virtual
dispatch via moncls->vprintf.

The dev_print() callbacks are temporarily using the MONITOR_HMP(mon)
cast, they are fixed in the following commits.

Early return in qemu_vprintf() if "hmp" is NULL, relying on
monitor_hmp_vprintf() handling NULL case is a bit uncommon.

Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-ID: <20260828-qemu-no-hmp-v5-37-9227de146347@redhat.com>
2026-08-29 12:07:45 +04:00
Marc-André Lureau 06c1600b55 monitor: make hmp_handle_error() take MonitorHMP
Mostly mechanical, with a few adjustments around it.

Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Dr. David Alan Gilbert <dave@treblig.org>
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-ID: <20260828-qemu-no-hmp-v5-32-9227de146347@redhat.com>
2026-08-29 12:07:44 +04:00
Marc-André Lureau 139ffc1039 monitor: change HMPCommand cmd to take MonitorHMP
HMP commands are specific to the HMP monitor, so make the cmd function
pointer in HMPCommand take MonitorHMP * instead of Monitor *. This
strengthens type safety and makes the HMP-specific nature of these
handlers explicit.

Handler functions are renamed to take MonitorHMP *hmp, with a local
Monitor *mon = MONITOR(hmp) added where the body needs the base type.
Following patches will drop it, since most functions are HMP specific.

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Jason J. Herne <jjherne@linux.ibm.com>
Reviewed-by: Dr. David Alan Gilbert <dave@treblig.org>
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-ID: <20260828-qemu-no-hmp-v5-31-9227de146347@redhat.com>
2026-08-29 12:07:44 +04:00
Marc-André Lureau 7c2ecb4e5e system: guard HMP initialization paths with CONFIG_HMP
- disable default monitor when HMP is not available
- hide 'readline' from -mon help text
- error out on mux chardev monitor when no HMP
- skip HMP monitor terminal for gdb, return E01 for 'qRcmd' remote
  commands

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-ID: <20260828-qemu-no-hmp-v5-28-9227de146347@redhat.com>
2026-08-29 12:07:44 +04:00
Marc-André Lureau 4440cc2fe9 qtest: add qemu-io command to the qtest protocol
Add a "qemu-io" command to the qtest protocol so that tests can issue
block layer I/O commands without going through the HMP monitor's
"human-monitor-command" QMP, or use QMP at all.

Unfortunately, many tests will prefer to use QMP as they also monitor
and log other events. It's easier if it is pipelined in the same stream.

Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-ID: <20260828-qemu-no-hmp-v5-23-9227de146347@redhat.com>
2026-08-29 12:07:44 +04:00
Marc-André Lureau 0619bab6cf system: move gpa2hva() to system memory unit
The function is now used by SEV code path. Move it to physmem.c rather
than hmp-cmds.c.

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-ID: <20260828-qemu-no-hmp-v5-7-9227de146347@redhat.com>
2026-08-29 12:07:43 +04:00
Marc-André Lureau 451bdd977f vl: fix -monitor none prefix matching
Use g_strcmp0() for exact match instead of strncmp() which would
incorrectly treat any string starting with "none" as disabling
the monitor.

Fixes: 70e098af88 ("monitor: allow to disable the default monitor")
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-ID: <20260828-qemu-no-hmp-v5-2-9227de146347@redhat.com>
2026-08-29 12:07:43 +04:00
Ani Sinha 0102503dc5 system/memory: add a tracepoint for memory_region_finalize
cosmetic: add a tracepoint to track when memory regions are getting freed.
Useful for debugging and tracking all freed memory regions.

Reviewed-by: Peter Xu <peterx@redhat.com>
Signed-off-by: Ani Sinha <anisinha@redhat.com>
Message-ID: <20260817142010.80693-5-anisinha@redhat.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2026-08-20 16:40:33 +02:00
Philippe Mathieu-Daudé f036b28896 system: Move runstate-related code from cpus.c to runstate.c
Keep cpus.c focused on vCPUs handling, move code related to
VM state to runstate.c where similar code lives.

Fix few checkpatch.pl warnings:

  WARNING: Block comments use a leading /* on a separate line
  WARNING: Block comments use * on subsequent lines
  #327: FILE: system/runstate.c:541:
  +/* does a state transition even if the VM is already stopped,
  +   current state is forgotten forever */

Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <20260812211708.92824-17-philmd@oss.qualcomm.com>
2026-08-16 16:32:42 +02:00
Philippe Mathieu-Daudé 259c2aae8d system: Extract QMP memsave/pmemsave commands to physmem-qmp-cmds.c
Keep cpus.c related to vCPU scheduling, move the QMP handlers
related to dumping physical memory to file to their own unit.
Fix a pair of checkpatch.pl errors doing so:

  ERROR: braces {} are necessary for all arms of this statement
  #185: FILE: system/physmem-qmp-cmds.c:51:
  +        if (l > size)
  [...]

Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <20260812211708.92824-16-philmd@oss.qualcomm.com>
2026-08-16 16:32:42 +02:00
Philippe Mathieu-Daudé 5bd649ccf9 system: Move qmp_inject_nmi() to hw/core/machine-qmp-cmds.c
We figured NMI relates to machines (for their machine-specific
handling), so move the 'inject-nmi' QMP handler with the rest
of machine ones, in hw/core/machine-qmp-cmds.c.

Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <20260812211708.92824-15-philmd@oss.qualcomm.com>
2026-08-16 16:32:42 +02:00
Philippe Mathieu-Daudé c339d8459e system/dirtylimit: Extract HMP code to dirtylimit-hmp-cmds.c
Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Hyman Huang <yong.huang@bitdeer.com>
Message-Id: <20260812211708.92824-14-philmd@oss.qualcomm.com>
2026-08-16 16:32:42 +02:00