qemu/hw/virtio
David Hildenbrand 713484d038 virtio-mem: unplug memory only during system resets, not device resets
We recently converted from the LegacyReset to the new reset framework
in commit c009a311e9 ("virtio-mem: Use new Resettable framework instead
of LegacyReset") to be able to use the ResetType to filter out wakeup
resets.

However, this change had an undesired implications: as we override the
Resettable interface methods in VirtIOMEMClass, the reset handler will
not only get called during system resets (i.e., qemu_devices_reset())
but also during any direct or indirect device rests (e.g.,
device_cold_reset()).

Further, we might now receive two reset callbacks during
qemu_devices_reset(), first when reset by a parent and later when reset
directly.

The memory state of virtio-mem devices is rather special: it's supposed to
be persistent/unchanged during most resets (similar to resetting a hard
disk will not destroy the data), unless actually cold-resetting the whole
system (different to a hard disk where a reboot will not destroy the data):
ripping out system RAM is something guest OSes don't particularly enjoy,
but we want to detect when rebooting to an OS that does not support
virtio-mem and wouldn't be able to detect+use the memory -- and we want
to force-defragment hotplugged memory to also shrink the usable device
memory region. So we rally want to catch system resets to do that.

On supported targets (e.g., x86), getting a cold reset on the
device/parent triggers is not that easy (but looks like PCI code
might trigger it), so this implication went unnoticed.

However, with upcoming s390x support it is problematic: during
kdump, s390x triggers a subsystem reset, ending up in
s390_machine_reset() and calling only subsystem_reset() instead of
qemu_devices_reset() -- because it's not a full system reset.

In subsystem_reset(), s390x performs a device_cold_reset() of any
TYPE_VIRTUAL_CSS_BRIDGE device, which ends up resetting all children,
including the virtio-mem device. Consequently, we wrongly detect a system
reset and unplug all device memory, resulting in hotplugged memory not
getting included in the crash dump -- undesired.

We really must not mess with hotplugged memory state during simple
device resets. To fix, create+register a new reset object that will only
get triggered during qemu_devices_reset() calls, but not during any other
resets as it is logically not the child of any other object.

Message-ID: <20241025104103.342188-1-david@redhat.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Cc: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Juraj Marcin <jmarcin@redhat.com>
Cc: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: David Hildenbrand <david@redhat.com>
2024-12-21 15:59:59 +01:00
..
cbor-helpers.c device/virtio-nsm: Support for Nitro Secure Module device 2024-10-31 18:28:32 +01:00
Kconfig device/virtio-nsm: Support for Nitro Secure Module device 2024-10-31 18:28:32 +01:00
meson.build device/virtio-nsm: Support for Nitro Secure Module device 2024-10-31 18:28:32 +01:00
trace-events virtio-iommu: Add trace point on virtio_iommu_detach_endpoint_from_domain 2024-07-22 20:15:42 -04:00
trace.h trace: switch position of headers to what Meson requires 2020-08-21 06:18:24 -04:00
vdpa-dev-pci.c vdpa: add vdpa-dev-pci support 2022-12-21 06:35:28 -05:00
vdpa-dev.c hw/virtio: Constify all Property 2024-12-15 12:56:40 -06:00
vhost-backend.c vhost: Add worker backend callouts 2023-12-25 11:34:55 -05:00
vhost-iova-tree.c util: accept iova_tree_remove_parameter by value 2022-09-02 10:22:39 +08:00
vhost-iova-tree.h util: accept iova_tree_remove_parameter by value 2022-09-02 10:22:39 +08:00
vhost-scsi-pci.c hw/virtio: Constify all Property 2024-12-15 12:56:40 -06:00
vhost-shadow-virtqueue.c hw/virtio: freeing leaked memory from vhost_svq_get_buf in vhost_svq_poll 2024-10-02 16:14:29 +04:00
vhost-shadow-virtqueue.h vhost: Expose vhost_svq_available_slots() 2023-10-18 10:41:50 -04:00
vhost-stub.c vhost: Add vhost_get_max_memslots() 2023-10-12 14:15:22 +02:00
vhost-user-base.c hw/virtio: Free vqs after vhost_dev_cleanup() 2024-07-01 17:16:05 -04:00
vhost-user-blk-pci.c hw/virtio: Constify all Property 2024-12-15 12:56:40 -06:00
vhost-user-device-pci.c virtio: split into vhost-user-base and vhost-user-device 2024-02-14 06:01:39 -05:00
vhost-user-device.c hw/virtio: Constify all Property 2024-12-15 12:56:40 -06:00
vhost-user-fs-pci.c hw/virtio: Constify all Property 2024-12-15 12:56:40 -06:00
vhost-user-fs.c hw/virtio: Constify all Property 2024-12-15 12:56:40 -06:00
vhost-user-gpio-pci.c hw/virtio: add vhost-user-gpio-pci boilerplate 2022-10-07 09:41:51 -04:00
vhost-user-gpio.c hw/virtio: Constify all Property 2024-12-15 12:56:40 -06:00
vhost-user-i2c-pci.c hw/virtio: move virtio-pci.h into shared include space 2022-05-16 04:38:40 -04:00
vhost-user-i2c.c hw/virtio: Constify all Property 2024-12-15 12:56:40 -06:00
vhost-user-input-pci.c hw/virtio: derive vhost-user-input from vhost-user-base 2024-02-14 06:09:32 -05:00
vhost-user-input.c hw/virtio: Constify all Property 2024-12-15 12:56:40 -06:00
vhost-user-rng-pci.c hw/virtio: Constify all Property 2024-12-15 12:56:40 -06:00
vhost-user-rng.c hw/virtio: Constify all Property 2024-12-15 12:56:40 -06:00
vhost-user-scmi-pci.c hw/virtio: Add vhost-user-scmi-pci boilerplate 2023-07-10 16:17:08 -04:00
vhost-user-scmi.c hw/virtio: Constify all Property 2024-12-15 12:56:40 -06:00
vhost-user-scsi-pci.c hw/virtio: Constify all Property 2024-12-15 12:56:40 -06:00
vhost-user-snd-pci.c hw/virtio: add vhost-user-snd and vhost-user-snd-pci devices 2024-02-14 06:09:03 -05:00
vhost-user-snd.c hw/virtio: Constify all Property 2024-12-15 12:56:40 -06:00
vhost-user-vsock-pci.c hw/virtio: Constify all Property 2024-12-15 12:56:40 -06:00
vhost-user-vsock.c hw/virtio: Constify all Property 2024-12-15 12:56:40 -06:00
vhost-user.c vhost-user: fix shared object return values 2024-11-04 16:03:25 -05:00
vhost-vdpa.c util/hexdump: Add unit_len and block_len to qemu_hexdump_line 2024-06-05 12:14:18 -07:00
vhost-vsock-common.c hw/virtio: Constify all Property 2024-12-15 12:56:40 -06:00
vhost-vsock-pci.c hw/virtio: Constify all Property 2024-12-15 12:56:40 -06:00
vhost-vsock.c hw/virtio: Constify all Property 2024-12-15 12:56:40 -06:00
vhost.c vhost: fail device start if iotlb update fails 2024-11-26 17:18:07 -05:00
virtio-9p-pci.c hw/virtio: Constify all Property 2024-12-15 12:56:40 -06:00
virtio-acpi.c license: Update deprecated SPDX tag GPL-2.0+ to GPL-2.0-or-later 2024-09-20 10:11:59 +03:00
virtio-balloon-pci.c hw/virtio: move virtio-pci.h into shared include space 2022-05-16 04:38:40 -04:00
virtio-balloon.c hw/virtio: Constify all Property 2024-12-15 12:56:40 -06:00
virtio-blk-pci.c hw/virtio: Constify all Property 2024-12-15 12:56:40 -06:00
virtio-bus.c virtio: stop ioeventfd on reset 2022-06-14 16:50:30 +02:00
virtio-config-io.c hw/virtio: Extract config read/write accessors to virtio-config-io.c 2022-12-21 07:32:24 -05:00
virtio-crypto-pci.c hw/virtio: Constify all Property 2024-12-15 12:56:40 -06:00
virtio-crypto.c hw/virtio: Constify all Property 2024-12-15 12:56:40 -06:00
virtio-hmp-cmds.c virtio: Move HMP commands from monitor/ to hw/virtio/ 2023-02-04 07:56:54 +01:00
virtio-input-host-pci.c hw/virtio: move virtio-pci.h into shared include space 2022-05-16 04:38:40 -04:00
virtio-input-pci.c hw/virtio: Constify all Property 2024-12-15 12:56:40 -06:00
virtio-iommu-pci.c hw/virtio: Constify all Property 2024-12-15 12:56:40 -06:00
virtio-iommu.c hw/virtio: Constify all Property 2024-12-15 12:56:40 -06:00
virtio-md-pci.c hw/mem/memory-device: Remove legacy_align from memory_device_pre_plug() 2024-06-19 12:40:49 +02:00
virtio-md-stubs.c hw/virtio: move stubs out of stubs/ 2024-04-18 11:17:27 +02:00
virtio-mem-pci.c virtio-mem: Expose device memory dynamically via multiple memslots if enabled 2023-10-12 14:15:22 +02:00
virtio-mem-pci.h virtio-md-pci: New parent type for virtio-mem-pci and virtio-pmem-pci 2023-07-12 09:27:25 +02:00
virtio-mem.c virtio-mem: unplug memory only during system resets, not device resets 2024-12-21 15:59:59 +01:00
virtio-mmio.c hw/virtio: Constify all Property 2024-12-15 12:56:40 -06:00
virtio-net-pci.c hw/virtio: Constify all Property 2024-12-15 12:56:40 -06:00
virtio-nsm-pci.c device/virtio-nsm: Support for Nitro Secure Module device 2024-10-31 18:28:32 +01:00
virtio-nsm.c hw/virtio: Constify all Property 2024-12-15 12:56:40 -06:00
virtio-pci.c hw/virtio: Constify all Property 2024-12-15 12:56:40 -06:00
virtio-pmem-pci.c virtio-md-pci: New parent type for virtio-mem-pci and virtio-pmem-pci 2023-07-12 09:27:25 +02:00
virtio-pmem-pci.h virtio-md-pci: New parent type for virtio-mem-pci and virtio-pmem-pci 2023-07-12 09:27:25 +02:00
virtio-pmem.c hw/virtio: Constify all Property 2024-12-15 12:56:40 -06:00
virtio-qmp.c virtio-mem: Add support for suspend+wake-up with plugged memory 2024-09-24 11:33:35 +02:00
virtio-qmp.h qmp: remove virtio_list, search QOM tree instead 2023-10-04 04:54:24 -04:00
virtio-rng-pci.c hw/virtio: Constify all Property 2024-12-15 12:56:40 -06:00
virtio-rng.c hw/virtio: Constify all Property 2024-12-15 12:56:40 -06:00
virtio-scsi-pci.c hw/virtio: Constify all Property 2024-12-15 12:56:40 -06:00
virtio-serial-pci.c hw/virtio: Constify all Property 2024-12-15 12:56:40 -06:00
virtio-stub.c qmp: add QMP command x-query-virtio-queue-element 2022-10-09 16:38:45 -04:00
virtio.c hw/virtio: Constify all Property 2024-12-15 12:56:40 -06:00