qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Juraj Marcin <jmarcin@redhat.com>
To: qemu-devel@nongnu.org
Cc: David Hildenbrand <david@redhat.com>,
	Peter Maydell <peter.maydell@linaro.org>
Subject: [PATCH 4/4] virtio-mem: Add support for suspend+wake-up with plugged memory
Date: Tue,  6 Aug 2024 18:07:54 +0200	[thread overview]
Message-ID: <20240806160756.182524-5-jmarcin@redhat.com> (raw)
In-Reply-To: <20240806160756.182524-1-jmarcin@redhat.com>

Before, the virtio-mem device would unplug all the memory with any reset
of the device, including during the wake-up of the guest from a
suspended state. Due to this, the virtio-mem driver in the Linux kernel
disallowed suspend-to-ram requests in the guest when the
VIRTIO_MEM_F_PERSISTENT_SUSPEND feature is not exposed by QEMU.

This patch adds the code to skip the reset on wake-up and exposes
theVIRTIO_MEM_F_PERSISTENT_SUSPEND feature to the guest kernel driver
when suspending is possible in QEMU (currently only x86).

Signed-off-by: Juraj Marcin <jmarcin@redhat.com>
---
 hw/virtio/virtio-mem.c | 10 ++++++++++
 hw/virtio/virtio-qmp.c |  3 +++
 2 files changed, 13 insertions(+)

diff --git a/hw/virtio/virtio-mem.c b/hw/virtio/virtio-mem.c
index 4f2fd7dc2e..d373eb0028 100644
--- a/hw/virtio/virtio-mem.c
+++ b/hw/virtio/virtio-mem.c
@@ -883,6 +883,9 @@ static uint64_t virtio_mem_get_features(VirtIODevice *vdev, uint64_t features,
     if (vmem->unplugged_inaccessible == ON_OFF_AUTO_ON) {
         virtio_add_feature(&features, VIRTIO_MEM_F_UNPLUGGED_INACCESSIBLE);
     }
+    if (qemu_wakeup_suspend_enabled()) {
+        virtio_add_feature(&features, VIRTIO_MEM_F_PERSISTENT_SUSPEND);
+    }
     return features;
 }
 
@@ -1841,6 +1844,13 @@ static void virtio_mem_system_reset_hold(Object *obj, ResetType type)
 {
     VirtIOMEM *vmem = VIRTIO_MEM(obj);
 
+    /*
+     * When waking up from standby/suspend-to-ram, do not unplug any memory.
+     */
+    if (type == RESET_TYPE_WAKEUP) {
+        return;
+    }
+
     /*
      * During usual resets, we will unplug all memory and shrink the usable
      * region size. This is, however, not possible in all scenarios. Then,
diff --git a/hw/virtio/virtio-qmp.c b/hw/virtio/virtio-qmp.c
index 1dd96ed20f..cccc6fe761 100644
--- a/hw/virtio/virtio-qmp.c
+++ b/hw/virtio/virtio-qmp.c
@@ -450,6 +450,9 @@ static const qmp_virtio_feature_map_t virtio_mem_feature_map[] = {
     FEATURE_ENTRY(VIRTIO_MEM_F_UNPLUGGED_INACCESSIBLE, \
             "VIRTIO_MEM_F_UNPLUGGED_INACCESSIBLE: Unplugged memory cannot be "
             "accessed"),
+    FEATURE_ENTRY(VIRTIO_MEM_F_PERSISTENT_SUSPEND, \
+            "VIRTIO_MEM_F_PERSISTENT_SUSPND: Plugged memory will remain "
+            "plugged when suspending+resuming"),
     { -1, "" }
 };
 #endif
-- 
2.45.2



  parent reply	other threads:[~2024-08-06 16:11 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-06 16:07 [PATCH 0/4] virtio-mem: Implement support for suspend+wake-up with plugged memory Juraj Marcin
2024-08-06 16:07 ` [PATCH 1/4] reset: Use ResetType for qemu_devices_reset() and MachineClass->reset() Juraj Marcin
2024-08-06 16:39   ` David Hildenbrand
2024-08-07 10:03     ` Juraj Marcin
2024-08-08 12:32   ` Peter Maydell
2024-08-06 16:07 ` [PATCH 2/4] reset: Add RESET_TYPE_WAKEUP Juraj Marcin
2024-08-06 16:41   ` David Hildenbrand
2024-08-08 12:18   ` Peter Maydell
2024-08-08 15:28     ` Juraj Marcin
2024-08-08 15:31       ` David Hildenbrand
2024-08-08 15:56         ` Peter Maydell
2024-08-08 16:04           ` David Hildenbrand
2024-08-08 16:17             ` Peter Maydell
2024-08-08 16:29               ` David Hildenbrand
2024-08-08 17:30                 ` Peter Maydell
2024-08-08 18:07                   ` David Hildenbrand
2024-08-06 16:07 ` [PATCH 3/4] virtio-mem: Implement Resettable interface instead of using LegacyReset Juraj Marcin
2024-08-06 16:42   ` David Hildenbrand
2024-08-08 12:25   ` Peter Maydell
2024-08-08 12:37     ` David Hildenbrand
2024-08-08 15:47       ` Peter Maydell
2024-08-09 13:06         ` Juraj Marcin
2024-08-06 16:07 ` Juraj Marcin [this message]
2024-08-06 16:43   ` [PATCH 4/4] virtio-mem: Add support for suspend+wake-up with plugged memory 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=20240806160756.182524-5-jmarcin@redhat.com \
    --to=jmarcin@redhat.com \
    --cc=david@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).