qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: David Hildenbrand <david@redhat.com>, qemu-devel@nongnu.org
Cc: "Michael S. Tsirkin" <mst@redhat.com>,
	Juraj Marcin <jmarcin@redhat.com>,
	 Peter Maydell <peter.maydell@linaro.org>
Subject: Re: [PATCH v1] virtio-mem: unplug memory only during system resets, not device resets
Date: Fri, 8 Nov 2024 14:37:59 +0000	[thread overview]
Message-ID: <9100ea2c-21e4-4f04-91fa-8b56986abcdf@linaro.org> (raw)
In-Reply-To: <20241025104103.342188-1-david@redhat.com>

Hi David,

On 25/10/24 11:41, David Hildenbrand wrote:
> We recently converted from the LegacyReset to the new reset framework
> in commit c009a311e939 ("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.
> 
> 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>
> ---
>   hw/virtio/virtio-mem.c         | 103 +++++++++++++++++++++++----------
>   include/hw/virtio/virtio-mem.h |  12 +++-
>   2 files changed, 83 insertions(+), 32 deletions(-)


> +OBJECT_DEFINE_SIMPLE_TYPE_WITH_INTERFACES(VirtioMemSystemReset, virtio_mem_system_reset, VIRTIO_MEM_SYSTEM_RESET, OBJECT, { TYPE_RESETTABLE_INTERFACE }, { })

Please fix style when applying :)

> diff --git a/include/hw/virtio/virtio-mem.h b/include/hw/virtio/virtio-mem.h
> index a1af144c28..abde1c4101 100644
> --- a/include/hw/virtio/virtio-mem.h
> +++ b/include/hw/virtio/virtio-mem.h


> +struct VirtioMemSystemReset {
> +    Object parent;

And add a newline here, thanks!

>       ResettableState reset_state;
> +    VirtIOMEM *vmem;
>   };
>   
>   struct VirtIOMEMClass {



  parent reply	other threads:[~2024-11-08 14:38 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-25 10:41 [PATCH v1] virtio-mem: unplug memory only during system resets, not device resets David Hildenbrand
2024-11-08 10:46 ` David Hildenbrand
2024-11-08 11:52 ` Michael S. Tsirkin
2024-11-08 14:37 ` Philippe Mathieu-Daudé [this message]
2024-11-08 14:57   ` David Hildenbrand

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9100ea2c-21e4-4f04-91fa-8b56986abcdf@linaro.org \
    --to=philmd@linaro.org \
    --cc=david@redhat.com \
    --cc=jmarcin@redhat.com \
    --cc=mst@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).