qemu-e2k/hw/virtio
David Hildenbrand 364eff6885 virtio-mem: fix division by zero in virtio_mem_activate_memslots_to_plug()
When running with "dynamic-memslots=off", we enter
virtio_mem_activate_memslots_to_plug() to return immediately again
because "vmem->dynamic_memslots == false". However, the compiler might
not optimize out calculating start_idx+end_idx, where we divide by
vmem->memslot_size. In such a configuration, the memslot size is 0 and
we'll get a division by zero:

    (qemu) qom-set vmem0 requested-size 3G
    (qemu) q35.sh: line 38: 622940 Floating point exception(core dumped)

The same is true for virtio_mem_deactivate_unplugged_memslots(), however
we never really reach that code without a prior
virtio_mem_activate_memslots_to_plug() call.

Let's fix it by simply calling these functions only with
"dynamic-memslots=on".

This was found when using a debug build of QEMU.

Message-ID: <20231023111341.219317-1-david@redhat.com>
Reprted-by: Mario Casquero <mcasquer@redhat.com>
Fixes: 177f9b1ee4 ("virtio-mem: Expose device memory dynamically via multiple memslots if enabled")
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Maciej S. Szmigiero <maciej.szmigiero@oracle.com>
Tested-by: Mario Casquero <mcasquer@redhat.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
2023-11-13 09:35:44 +01:00
..
Kconfig
meson.build
trace-events virtio-iommu: Consolidate host reserved regions and property set ones 2023-11-03 09:20:31 +01:00
trace.h
vdpa-dev-pci.c
vdpa-dev.c
vhost-backend.c vhost-backend: remove vhost_kernel_reset_device() 2023-10-22 05:18:16 -04:00
vhost-iova-tree.c
vhost-iova-tree.h
vhost-scsi-pci.c
vhost-shadow-virtqueue.c vhost: Expose vhost_svq_available_slots() 2023-10-18 10:41:50 -04:00
vhost-shadow-virtqueue.h vhost: Expose vhost_svq_available_slots() 2023-10-18 10:41:50 -04:00
vhost-stub.c
vhost-user-blk-pci.c
vhost-user-device-pci.c
vhost-user-device.c
vhost-user-fs-pci.c
vhost-user-fs.c vhost-user-fs: Implement internal migration 2023-11-07 03:39:10 -05:00
vhost-user-gpio-pci.c
vhost-user-gpio.c vhost-user: fix lost reconnect 2023-10-22 05:18:17 -04:00
vhost-user-i2c-pci.c
vhost-user-i2c.c
vhost-user-input-pci.c
vhost-user-rng-pci.c
vhost-user-rng.c
vhost-user-scmi-pci.c
vhost-user-scmi.c
vhost-user-scsi-pci.c
vhost-user-vsock-pci.c
vhost-user-vsock.c
vhost-user.c vhost-user: Interface for migration state transfer 2023-11-07 03:39:10 -05:00
vhost-vdpa.c
vhost-vsock-common.c
vhost-vsock-pci.c
vhost-vsock.c
vhost.c vhost: Add high-level state save/load functions 2023-11-07 03:39:10 -05:00
virtio-9p-pci.c
virtio-balloon-pci.c
virtio-balloon.c
virtio-blk-pci.c
virtio-bus.c
virtio-config-io.c
virtio-crypto-pci.c
virtio-crypto.c
virtio-hmp-cmds.c
virtio-input-host-pci.c
virtio-input-pci.c
virtio-iommu-pci.c virtio-iommu: Rename reserved_regions into prop_resv_regions 2023-11-03 09:20:31 +01:00
virtio-iommu.c hw/pci: modify pci_setup_iommu() to set PCIIOMMUOps 2023-11-03 09:20:31 +01:00
virtio-md-pci.c
virtio-mem-pci.c
virtio-mem-pci.h
virtio-mem.c virtio-mem: fix division by zero in virtio_mem_activate_memslots_to_plug() 2023-11-13 09:35:44 +01:00
virtio-mmio.c kvm: require KVM_CAP_IOEVENTFD and KVM_CAP_IOEVENTFD_ANY_LENGTH 2023-10-25 17:35:15 +02:00
virtio-net-pci.c
virtio-pci.c kvm: require KVM_CAP_IOEVENTFD and KVM_CAP_IOEVENTFD_ANY_LENGTH 2023-10-25 17:35:15 +02:00
virtio-pmem-pci.c
virtio-pmem-pci.h
virtio-pmem.c Revert "hw/virtio/virtio-pmem: Replace impossible check by assertion" 2023-11-06 13:53:59 +01:00
virtio-qmp.c
virtio-qmp.h
virtio-rng-pci.c
virtio-rng.c
virtio-scsi-pci.c
virtio-serial-pci.c
virtio-stub.c
virtio.c virtio: use defer_call() in virtio_irqfd_notify() 2023-10-31 15:42:14 +01:00