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/hw
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
..
acpi qapi/acpi-hest: add an interface to do generic CPER error injection 2 months ago
adc
arm hw/arm/aspeed: Rename and export connect_serial_hds_to_uarts() as aspeed_connect_serial_hds_to_uarts() 1 month ago
audio audio: move audio.h under include/qemu/ 1 month ago
block block: enable stats-intervals for storage devices 1 month ago
char * char: rename CharBackend->CharFrontend 1 month ago
core exec/cpu: Declare cpu_memory_rw_debug() in 'hw/core/cpu.h' and document 1 month ago
cpu
cxl hw/cxl: mailbox-utils: 0x5604 - FMAPI Initiate DC Add 5 months ago
display audio: move audio.h under include/qemu/ 1 month ago
dma
firmware hw/smbios: allow clearing the VM bit in SMBIOS table 0 2 months ago
fsi
gpio
hyperv include/hw/hyperv: Add MSHV ABI header definitions 2 months ago
i2c
i386 intel_iommu: Handle PASID cache invalidation 4 weeks ago
ide
input qom: remove redundant typedef when use OBJECT_DECLARE_SIMPLE_TYPE 1 month ago
intc hw/int/loongarch: Include missing 'system/memory.h' header 1 month ago
ipack
ipmi
isa audio: move audio.h under include/qemu/ 1 month ago
loongarch hw/loongarch/virt: Sort order by hardware device base address 2 months ago
m68k
mem
mips
misc hw/southbridge/lasi: Correct LasiState parent 2 weeks ago
net hw/hppa: Enable LASI i82596 network on 715 machine 1 month ago
nubus
nvram hw/core/register: remove the calls to `register_finalize_block' 1 month ago
openrisc
pci hw/pci: Make msix_init take a uint32_t for nentries 1 week ago
pci-bridge
pci-host qom: remove redundant typedef when use OBJECT_DECLARE_SIMPLE_TYPE 1 month ago
ppc ppc/spapr: Cleanup MSI IRQ number handling 1 month ago
remote
riscv hw/riscv: Widen OpenSBI dynamic info struct 1 month ago
rtc
rx
s390x hw/s390x/ccw: Remove SCLPDevice::increment_size field 1 month ago
scsi qom: remove redundant typedef when use OBJECT_DECLARE_SIMPLE_TYPE 1 month ago
sd hw/sd/sdcard: Remove support for spec v1.10 3 months ago
sensor
sh4
southbridge x86: ich9: fix default value of 'No Reboot' bit in GCS 2 months ago
sparc
ssi hw/ssi: Document ssi_transfer() method 3 months ago
timer hw/pcspk: use explicitly the required PIT types 1 month ago
tricore
uefi hw/uefi: Include missing 'system/memory.h' header 1 month ago
usb
vfio qom: remove redundant typedef when use OBJECT_DECLARE_SIMPLE_TYPE 1 month ago
virtio * char: rename CharBackend->CharFrontend 1 month ago
vmapple
watchdog
xen hw/xen: Avoid non-inclusive language in params.h 1 month ago
xtensa
boards.h hw/boards: Introduce DEFINE_MACHINE_WITH_INTERFACE_ARRAY() macro 1 month ago
clock.h
elf_ops.h.inc
fw-path-provider.h
hotplug.h
hw.h
irq.h hw/irq: New qemu_init_irq_child() function 3 months ago
loader-fit.h
loader.h hw/core/loader: capture Error from load_image_targphys 1 month ago
nmi.h
or-irq.h
platform-bus.h
ptimer.h
qdev-clock.h
qdev-core.h hw/qdev: Have qdev_get_gpio_out_connector() take const DeviceState arg 1 month ago
qdev-dma.h
qdev-properties-system.h audio: remove QEMUSoundCard 1 month ago
qdev-properties.h qdev: Change PropertyInfo method print() to return malloc'ed string 1 month ago
register.h hw/core/register: remove the `register_finalize_block' function 1 month ago
registerfields.h
resettable.h
stream.h
sysbus.h hw/sysbus: Have various helpers take a const SysBusDevice argument 1 month ago
usb.h
vmstate-if.h