* [QEMU PATCH v4 0/1] S3 support
@ 2023-07-20 12:08 Jiqian Chen
2023-07-20 12:08 ` [QEMU PATCH v4 1/1] virtgpu: do not destroy resources when guest suspend Jiqian Chen
2023-08-11 7:18 ` [QEMU PATCH v4 0/1] S3 support Chen, Jiqian
0 siblings, 2 replies; 3+ messages in thread
From: Jiqian Chen @ 2023-07-20 12:08 UTC (permalink / raw)
To: Gerd Hoffmann, Marc-André Lureau, Michael S . Tsirkin,
Robert Beckett, qemu-devel
Cc: xen-devel, Stefano Stabellini, Anthony PERARD,
Roger Pau Monné, Dr . David Alan Gilbert, Alex Deucher,
Christian Koenig, Stewart Hildebrand, Xenia Ragiadakou,
Honglei Huang, Julia Zhang, Huang Rui, Jiqian Chen
v4:
Hi all,
Thanks for Gerd Hoffmann's advice. V4 makes below changes:
* Use enum for freeze mode, so this can be extended with more
modes in the future.
* Rename functions and paratemers with "_S3" postfix.
And no functional changes.
latest version on kernel side:
https://lore.kernel.org/lkml/20230720115805.8206-1-Jiqian.Chen@amd.com/T/#t
Best regards,
Jiqian Chen.
v3:
link,
https://lore.kernel.org/qemu-devel/20230719074726.1613088-1-Jiqian.Chen@amd.com/T/#t
Hi all,
Thanks for Michael S. Tsirkin's advice. V3 makes below changes:
* Remove changes in file include/standard-headers/linux/virtio_gpu.h
I am not supposed to edit this file and it will be imported after
the patches of linux kernel was merged.
v2:
link,
https://lore.kernel.org/qemu-devel/20230630070016.841459-1-Jiqian.Chen@amd.com/T/#t
Hi all,
Thanks to Marc-André Lureau, Robert Beckett and Gerd Hoffmann for
their advice and guidance. V2 makes below changes:
* Change VIRTIO_CPU_CMD_STATUS_FREEZING to 0x0400 (<0x1000)
* Add virtio_gpu_device_unrealize to destroy resources to solve
potential memory leak problem. This also needs hot-plug support.
* Add a new feature flag VIRTIO_GPU_F_FREEZING, so that guest and
host can negotiate whenever freezing is supported or not.
v1:
link,
https://lore.kernel.org/qemu-devel/20230608025655.1674357-1-Jiqian.Chen@amd.com/
Hi all,
I am working to implement virtgpu S3 function on Xen.
Currently on Xen, if we start a guest who enables virtgpu, and then
run "echo mem > /sys/power/state" to suspend guest. And run
"sudo xl trigger <guest id> s3resume" to resume guest. We can find that
the guest kernel comes back, but the display doesn't. It just shown a
black screen.
Through reading codes, I founded that when guest was during suspending,
it called into Qemu to call virtio_gpu_gl_reset. In virtio_gpu_gl_reset,
it destroyed all resources and reset renderer. This made the display
gone after guest resumed.
I think we should keep resources or prevent they being destroyed when
guest is suspending. So, I add a new status named freezing to virtgpu,
and add a new ctrl message VIRTIO_GPU_CMD_STATUS_FREEZING to get
notification from guest. If freezing is set to true, and then Qemu will
realize that guest is suspending, it will not destroy resources and will
not reset renderer. If freezing is set to false, Qemu will do its origin
actions, and has no other impaction.
And now, display can come back and applications can continue their
status after guest resumes.
Jiqian Chen (1):
virtgpu: do not destroy resources when guest suspend
hw/display/virtio-gpu-base.c | 3 ++
hw/display/virtio-gpu-gl.c | 10 ++++++-
hw/display/virtio-gpu-virgl.c | 7 +++++
hw/display/virtio-gpu.c | 55 ++++++++++++++++++++++++++++++++--
hw/virtio/virtio.c | 3 ++
include/hw/virtio/virtio-gpu.h | 6 ++++
6 files changed, 81 insertions(+), 3 deletions(-)
--
2.34.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* [QEMU PATCH v4 1/1] virtgpu: do not destroy resources when guest suspend
2023-07-20 12:08 [QEMU PATCH v4 0/1] S3 support Jiqian Chen
@ 2023-07-20 12:08 ` Jiqian Chen
2023-08-11 7:18 ` [QEMU PATCH v4 0/1] S3 support Chen, Jiqian
1 sibling, 0 replies; 3+ messages in thread
From: Jiqian Chen @ 2023-07-20 12:08 UTC (permalink / raw)
To: Gerd Hoffmann, Marc-André Lureau, Michael S . Tsirkin,
Robert Beckett, qemu-devel
Cc: xen-devel, Stefano Stabellini, Anthony PERARD,
Roger Pau Monné, Dr . David Alan Gilbert, Alex Deucher,
Christian Koenig, Stewart Hildebrand, Xenia Ragiadakou,
Honglei Huang, Julia Zhang, Huang Rui, Jiqian Chen
After suspending and resuming guest VM, you will get
a black screen, and the display can't come back.
This is because when guest did suspending, it called
into qemu to call virtio_gpu_gl_reset. In function
virtio_gpu_gl_reset, it destroyed resources and reset
renderer, which were used for display. As a result,
guest's screen can't come back to the time when it was
suspended and only showed black.
So, this patch adds a new ctrl message
VIRTIO_GPU_CMD_SET_FREEZE_MODE to get notifications from
guest. If guest is during suspending, it sets freeze mode
of virtgpu to freeze_S3, this will prevent destroying
resources and resetting renderer when guest calls into
virtio_gpu_gl_reset. If guest is during resuming, it sets
freeze mode to unfreeze, and then virtio_gpu_gl_reset
will keep its origin actions and has no other impaction.
Due to this implemention needs cooperation with guest,
so it added a new feature flag VIRTIO_GPU_F_FREEZE_S3, so
that guest and host can negotiate whenever freeze_S3 is
supported or not.
Signed-off-by: Jiqian Chen <Jiqian.Chen@amd.com>
---
hw/display/virtio-gpu-base.c | 3 ++
hw/display/virtio-gpu-gl.c | 10 ++++++-
hw/display/virtio-gpu-virgl.c | 7 +++++
hw/display/virtio-gpu.c | 55 ++++++++++++++++++++++++++++++++--
hw/virtio/virtio.c | 3 ++
include/hw/virtio/virtio-gpu.h | 6 ++++
6 files changed, 81 insertions(+), 3 deletions(-)
diff --git a/hw/display/virtio-gpu-base.c b/hw/display/virtio-gpu-base.c
index a29f191aa8..40ae4f9678 100644
--- a/hw/display/virtio-gpu-base.c
+++ b/hw/display/virtio-gpu-base.c
@@ -215,6 +215,9 @@ virtio_gpu_base_get_features(VirtIODevice *vdev, uint64_t features,
if (virtio_gpu_blob_enabled(g->conf)) {
features |= (1 << VIRTIO_GPU_F_RESOURCE_BLOB);
}
+ if (virtio_gpu_freeze_S3_enabled(g->conf)) {
+ features |= (1 << VIRTIO_GPU_F_FREEZE_S3);
+ }
return features;
}
diff --git a/hw/display/virtio-gpu-gl.c b/hw/display/virtio-gpu-gl.c
index e06be60dfb..cb418dae9a 100644
--- a/hw/display/virtio-gpu-gl.c
+++ b/hw/display/virtio-gpu-gl.c
@@ -100,7 +100,15 @@ static void virtio_gpu_gl_reset(VirtIODevice *vdev)
*/
if (gl->renderer_inited && !gl->renderer_reset) {
virtio_gpu_virgl_reset_scanout(g);
- gl->renderer_reset = true;
+ /*
+ * If guest is suspending, we shouldn't reset renderer,
+ * otherwise, the display can't come back to the time when
+ * it was suspended after guest was resumed.
+ */
+ if (!virtio_gpu_freeze_S3_enabled(g->parent_obj.conf) ||
+ g->freeze_mode == VIRTIO_GPU_FREEZE_MODE_UNFREEZE) {
+ gl->renderer_reset = true;
+ }
}
}
diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c
index 73cb92c8d5..fc1971be70 100644
--- a/hw/display/virtio-gpu-virgl.c
+++ b/hw/display/virtio-gpu-virgl.c
@@ -464,6 +464,13 @@ void virtio_gpu_virgl_process_cmd(VirtIOGPU *g,
case VIRTIO_GPU_CMD_GET_EDID:
virtio_gpu_get_edid(g, cmd);
break;
+ case VIRTIO_GPU_CMD_SET_FREEZE_MODE:
+ if (virtio_gpu_freeze_S3_enabled(g->parent_obj.conf)) {
+ virtio_gpu_cmd_set_freeze_mode(g, cmd);
+ } else {
+ cmd->error = VIRTIO_GPU_RESP_ERR_INVALID_PARAMETER;
+ }
+ break;
default:
cmd->error = VIRTIO_GPU_RESP_ERR_UNSPEC;
break;
diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c
index 5e15c79b94..dcf83379a8 100644
--- a/hw/display/virtio-gpu.c
+++ b/hw/display/virtio-gpu.c
@@ -373,6 +373,16 @@ static void virtio_gpu_resource_create_blob(VirtIOGPU *g,
QTAILQ_INSERT_HEAD(&g->reslist, res, next);
}
+void virtio_gpu_cmd_set_freeze_mode(VirtIOGPU *g,
+ struct virtio_gpu_ctrl_command *cmd)
+{
+ struct virtio_gpu_set_freeze_mode sf;
+
+ VIRTIO_GPU_FILL_CMD(sf);
+ virtio_gpu_bswap_32(&sf, sizeof(sf));
+ g->freeze_mode = sf.freeze_mode;
+}
+
static void virtio_gpu_disable_scanout(VirtIOGPU *g, int scanout_id)
{
struct virtio_gpu_scanout *scanout = &g->parent_obj.scanout[scanout_id];
@@ -986,6 +996,13 @@ void virtio_gpu_simple_process_cmd(VirtIOGPU *g,
case VIRTIO_GPU_CMD_RESOURCE_DETACH_BACKING:
virtio_gpu_resource_detach_backing(g, cmd);
break;
+ case VIRTIO_GPU_CMD_SET_FREEZE_MODE:
+ if (virtio_gpu_freeze_S3_enabled(g->parent_obj.conf)) {
+ virtio_gpu_cmd_set_freeze_mode(g, cmd);
+ } else {
+ cmd->error = VIRTIO_GPU_RESP_ERR_INVALID_PARAMETER;
+ }
+ break;
default:
cmd->error = VIRTIO_GPU_RESP_ERR_UNSPEC;
break;
@@ -1344,6 +1361,29 @@ void virtio_gpu_device_realize(DeviceState *qdev, Error **errp)
QTAILQ_INIT(&g->reslist);
QTAILQ_INIT(&g->cmdq);
QTAILQ_INIT(&g->fenceq);
+
+ g->freeze_mode = VIRTIO_GPU_FREEZE_MODE_UNFREEZE;
+}
+
+static void virtio_gpu_device_unrealize(DeviceState *qdev)
+{
+ VirtIOGPU *g = VIRTIO_GPU(qdev);
+ struct virtio_gpu_simple_resource *res, *tmp;
+
+ /*
+ * This is to prevent memory leak in the situation that qemu is
+ * destroyed when guest is suspended. This also need hot-plug
+ * support.
+ */
+ if (virtio_gpu_freeze_S3_enabled(g->parent_obj.conf) &&
+ g->freeze_mode == VIRTIO_GPU_FREEZE_MODE_FREEZE_S3) {
+ QTAILQ_FOREACH_SAFE(res, &g->reslist, next, tmp) {
+ virtio_gpu_resource_destroy(g, res);
+ }
+ virtio_gpu_virgl_reset(g);
+ g->freeze_mode = VIRTIO_GPU_FREEZE_MODE_UNFREEZE;
+ }
+
}
void virtio_gpu_reset(VirtIODevice *vdev)
@@ -1352,8 +1392,16 @@ void virtio_gpu_reset(VirtIODevice *vdev)
struct virtio_gpu_simple_resource *res, *tmp;
struct virtio_gpu_ctrl_command *cmd;
- QTAILQ_FOREACH_SAFE(res, &g->reslist, next, tmp) {
- virtio_gpu_resource_destroy(g, res);
+ /*
+ * If guest is suspending, we shouldn't destroy resources,
+ * otherwise, the display can't come back to the time when
+ * it was suspended after guest was resumed.
+ */
+ if (!virtio_gpu_freeze_S3_enabled(g->parent_obj.conf) ||
+ g->freeze_mode == VIRTIO_GPU_FREEZE_MODE_UNFREEZE) {
+ QTAILQ_FOREACH_SAFE(res, &g->reslist, next, tmp) {
+ virtio_gpu_resource_destroy(g, res);
+ }
}
while (!QTAILQ_EMPTY(&g->cmdq)) {
@@ -1425,6 +1473,8 @@ static Property virtio_gpu_properties[] = {
256 * MiB),
DEFINE_PROP_BIT("blob", VirtIOGPU, parent_obj.conf.flags,
VIRTIO_GPU_FLAG_BLOB_ENABLED, false),
+ DEFINE_PROP_BIT("freeze_S3", VirtIOGPU, parent_obj.conf.flags,
+ VIRTIO_GPU_FLAG_FREEZE_S3_ENABLED, false),
DEFINE_PROP_END_OF_LIST(),
};
@@ -1441,6 +1491,7 @@ static void virtio_gpu_class_init(ObjectClass *klass, void *data)
vgbc->gl_flushed = virtio_gpu_handle_gl_flushed;
vdc->realize = virtio_gpu_device_realize;
+ vdc->unrealize = virtio_gpu_device_unrealize;
vdc->reset = virtio_gpu_reset;
vdc->get_config = virtio_gpu_get_config;
vdc->set_config = virtio_gpu_set_config;
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index eb6347ab5d..2a3c54f2c4 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -240,6 +240,9 @@ qmp_virtio_feature_map_t virtio_gpu_feature_map[] = {
FEATURE_ENTRY(VIRTIO_GPU_F_CONTEXT_INIT, \
"VIRTIO_GPU_F_CONTEXT_INIT: Context types and synchronization "
"timelines supported"),
+ FEATURE_ENTRY(VIRTIO_GPU_F_FREEZE_S3, \
+ "VIRTIO_GPU_F_FREEZE_S3: Freezing virtio-gpu and keeping resources"
+ "alive is supported."),
FEATURE_ENTRY(VHOST_F_LOG_ALL, \
"VHOST_F_LOG_ALL: Logging write descriptors supported"),
FEATURE_ENTRY(VHOST_USER_F_PROTOCOL_FEATURES, \
diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h
index 2e28507efe..141c48080f 100644
--- a/include/hw/virtio/virtio-gpu.h
+++ b/include/hw/virtio/virtio-gpu.h
@@ -90,6 +90,7 @@ enum virtio_gpu_base_conf_flags {
VIRTIO_GPU_FLAG_EDID_ENABLED,
VIRTIO_GPU_FLAG_DMABUF_ENABLED,
VIRTIO_GPU_FLAG_BLOB_ENABLED,
+ VIRTIO_GPU_FLAG_FREEZE_S3_ENABLED,
};
#define virtio_gpu_virgl_enabled(_cfg) \
@@ -102,6 +103,8 @@ enum virtio_gpu_base_conf_flags {
(_cfg.flags & (1 << VIRTIO_GPU_FLAG_DMABUF_ENABLED))
#define virtio_gpu_blob_enabled(_cfg) \
(_cfg.flags & (1 << VIRTIO_GPU_FLAG_BLOB_ENABLED))
+#define virtio_gpu_freeze_S3_enabled(_cfg) \
+ (_cfg.flags & (1 << VIRTIO_GPU_FLAG_FREEZE_S3_ENABLED))
struct virtio_gpu_base_conf {
uint32_t max_outputs;
@@ -173,6 +176,7 @@ struct VirtIOGPU {
uint64_t hostmem;
+ virtio_gpu_freeze_mode_t freeze_mode;
bool processing_cmdq;
QEMUTimer *fence_poll;
QEMUTimer *print_stats;
@@ -284,5 +288,7 @@ void virtio_gpu_virgl_reset_scanout(VirtIOGPU *g);
void virtio_gpu_virgl_reset(VirtIOGPU *g);
int virtio_gpu_virgl_init(VirtIOGPU *g);
int virtio_gpu_virgl_get_num_capsets(VirtIOGPU *g);
+void virtio_gpu_cmd_set_freeze_mode(VirtIOGPU *g,
+ struct virtio_gpu_ctrl_command *cmd);
#endif
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [QEMU PATCH v4 0/1] S3 support
2023-07-20 12:08 [QEMU PATCH v4 0/1] S3 support Jiqian Chen
2023-07-20 12:08 ` [QEMU PATCH v4 1/1] virtgpu: do not destroy resources when guest suspend Jiqian Chen
@ 2023-08-11 7:18 ` Chen, Jiqian
1 sibling, 0 replies; 3+ messages in thread
From: Chen, Jiqian @ 2023-08-11 7:18 UTC (permalink / raw)
To: Chen, Jiqian, Gerd Hoffmann, Marc-André Lureau,
Michael S . Tsirkin, Robert Beckett, qemu-devel@nongnu.org
Cc: xen-devel@lists.xenproject.org, Stefano Stabellini,
Anthony PERARD, Roger Pau Monné, Dr . David Alan Gilbert,
Deucher, Alexander, Koenig, Christian, Hildebrand, Stewart,
Xenia Ragiadakou, Huang, Honglei1, Zhang, Julia, Huang, Ray
Hi all,
Please forgive me for asking. Do you have any other comments on my latest version patches about virtio-gpu S3 on Xen? Looking forward to your reply.
On 2023/7/20 20:08, Jiqian Chen wrote:
> v4:
>
> Hi all,
> Thanks for Gerd Hoffmann's advice. V4 makes below changes:
> * Use enum for freeze mode, so this can be extended with more
> modes in the future.
> * Rename functions and paratemers with "_S3" postfix.
> And no functional changes.
>
> latest version on kernel side:
> https://lore.kernel.org/lkml/20230720115805.8206-1-Jiqian.Chen@amd.com/T/#t
>
> Best regards,
> Jiqian Chen.
>
>
> v3:
> link,
> https://lore.kernel.org/qemu-devel/20230719074726.1613088-1-Jiqian.Chen@amd.com/T/#t
>
> Hi all,
> Thanks for Michael S. Tsirkin's advice. V3 makes below changes:
> * Remove changes in file include/standard-headers/linux/virtio_gpu.h
> I am not supposed to edit this file and it will be imported after
> the patches of linux kernel was merged.
>
>
> v2:
> link,
> https://lore.kernel.org/qemu-devel/20230630070016.841459-1-Jiqian.Chen@amd.com/T/#t
>
> Hi all,
> Thanks to Marc-André Lureau, Robert Beckett and Gerd Hoffmann for
> their advice and guidance. V2 makes below changes:
>
> * Change VIRTIO_CPU_CMD_STATUS_FREEZING to 0x0400 (<0x1000)
> * Add virtio_gpu_device_unrealize to destroy resources to solve
> potential memory leak problem. This also needs hot-plug support.
> * Add a new feature flag VIRTIO_GPU_F_FREEZING, so that guest and
> host can negotiate whenever freezing is supported or not.
>
> v1:
> link,
> https://lore.kernel.org/qemu-devel/20230608025655.1674357-1-Jiqian.Chen@amd.com/
>
> Hi all,
> I am working to implement virtgpu S3 function on Xen.
>
> Currently on Xen, if we start a guest who enables virtgpu, and then
> run "echo mem > /sys/power/state" to suspend guest. And run
> "sudo xl trigger <guest id> s3resume" to resume guest. We can find that
> the guest kernel comes back, but the display doesn't. It just shown a
> black screen.
>
> Through reading codes, I founded that when guest was during suspending,
> it called into Qemu to call virtio_gpu_gl_reset. In virtio_gpu_gl_reset,
> it destroyed all resources and reset renderer. This made the display
> gone after guest resumed.
>
> I think we should keep resources or prevent they being destroyed when
> guest is suspending. So, I add a new status named freezing to virtgpu,
> and add a new ctrl message VIRTIO_GPU_CMD_STATUS_FREEZING to get
> notification from guest. If freezing is set to true, and then Qemu will
> realize that guest is suspending, it will not destroy resources and will
> not reset renderer. If freezing is set to false, Qemu will do its origin
> actions, and has no other impaction.
>
> And now, display can come back and applications can continue their
> status after guest resumes.
>
> Jiqian Chen (1):
> virtgpu: do not destroy resources when guest suspend
>
> hw/display/virtio-gpu-base.c | 3 ++
> hw/display/virtio-gpu-gl.c | 10 ++++++-
> hw/display/virtio-gpu-virgl.c | 7 +++++
> hw/display/virtio-gpu.c | 55 ++++++++++++++++++++++++++++++++--
> hw/virtio/virtio.c | 3 ++
> include/hw/virtio/virtio-gpu.h | 6 ++++
> 6 files changed, 81 insertions(+), 3 deletions(-)
>
--
Best regards,
Jiqian Chen.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-08-11 7:25 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-20 12:08 [QEMU PATCH v4 0/1] S3 support Jiqian Chen
2023-07-20 12:08 ` [QEMU PATCH v4 1/1] virtgpu: do not destroy resources when guest suspend Jiqian Chen
2023-08-11 7:18 ` [QEMU PATCH v4 0/1] S3 support Chen, Jiqian
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).