You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
qemu/include
Peter Maydell ef44cc0a76 hw/pci: Make msix_init take a uint32_t for nentries
msix_init() and msix_init_exclusive_bar() take an "unsigned short"
argument for the number of MSI-X vectors to try to use.  This is big
enough for the maximum permitted number of vectors, which is 2048.
Unfortunately, we have several devices (most notably virtio) which
allow the user to specify the desired number of vectors, and which
use uint32_t properties for this.  If the user sets the property to a
value that is too big for a uint16_t, the value will be truncated
when it is passed to msix_init(), and msix_init() may then return
success if the truncated value is a valid one.

The resulting mismatch between the number of vectors the msix code
thinks the device has and the number of vectors the device itself
thinks it has can cause assertions, such as the one in issue 2631,
where "-device virtio-mouse-pci,vectors=19923041" is interpreted by
msix as "97 vectors" and by the virtio-pci layer as "19923041
vectors"; a guest attempt to access vector 97 thus passes the
virtio-pci bounds checking and hits an essertion in
msix_vector_use().

Avoid this by making msix_init() and its wrapper function
msix_init_exclusive_bar() take the number of vectors as a uint32_t.
The erroneous command line will now produce the warning

 qemu-system-i386: -device virtio-mouse-pci,vectors=19923041:
   warning: unable to init msix vectors to 19923041

and proceed without crashing.  (The virtio device warns and falls
back to not using MSIX, rather than complaining that the option is
not a valid value this is the same as the existing behaviour for
values that are beyond the MSI-X maximum possible value but fit into
a 16-bit integer, like 2049.)

To ensure this doesn't result in potential overflows in calculation
of the BAR size in msix_init_exclusive_bar(), we duplicate the
nentries error-check from msix_init() at the top of
msix_init_exclusive_bar(), so we know nentries is sane before we
start using it.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2631
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Message-ID: <20251107131044.1321637-1-peter.maydell@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
1 week ago
..
accel accel/tcg: Add cpu_atomic_*_mmu for 16-byte xchg, fetch_and, fetch_or 3 months ago
authz
block hw/nvme: fix namespace atomic parameter setup 1 week ago
chardev char: rename CharBackend->CharFrontend 1 month ago
crypto crypto: support upto 5 parallel certificate identities 1 month ago
disas
exec exec/cpu: Declare cpu_memory_rw_debug() in 'hw/core/cpu.h' and document 1 month ago
fpu fpu: Move m68k_denormal fmt flag into floatx80_behaviour 9 months ago
gdbstub gdbstub/helpers: Replace TARGET_BIG_ENDIAN -> target_big_endian() 5 months ago
hw hw/pci: Make msix_init take a uint32_t for nentries 1 week ago
io qio: Add QIONetListener API for using AioContext 3 weeks ago
libdecnumber include/libdecnumber: replace FSF postal address with licenses URL 5 months ago
migration migration: vmsd errp handlers: return bool 1 month ago
monitor qdev: add qdev_find_default_bus() 1 month ago
net qom: remove redundant typedef when use OBJECT_DECLARE_SIMPLE_TYPE 1 month ago
qapi error: Kill @error_warn 2 months ago
qemu Merge crypto and other misc fixes / features 1 month ago
qobject qobject: make refcount atomic 1 month ago
qom qom: reverse order of instance_post_init calls 7 months ago
scsi
semihosting include/semihosting/common-semi: extract common_semi API 2 months ago
standard-headers linux-headers: Update to Linux v6.18-rc3 1 month ago
system block: use pwrite_zeroes_alignment when writing first sector 1 week ago
tcg tcg: Add tcg_gen_atomic_{xchg,fetch_and,fetch_or}_i128 3 months ago
ui ui/gtk: Add scale option 5 months ago
user accel/tcg: Add clear_flags argument to page_set_flags 2 months ago
elf.h elf: Add EF_MIPS_ARCH_ASE definitions 3 months ago
glib-compat.h include/glib-compat.h: Poison g_list_sort and g_slist_sort 7 months ago
qemu-io.h
qemu-main.h ui & main loop: Redesign of system-specific main thread event handling 11 months ago