Skip to contentSkip to conversation

Add new feature VIRTIO_F_PRESERVE_RESOURCES

PATCH In review Jiqian Chen 4 participants 38 messages Oct 21, 2023 – Jan 16, 2024

lore
Share & tools
lore
#0 lore raw

v6 cover Add new feature VIRTIO_F_PRESERVE_RESOURCES

Hi all,
This is the version 6, thank Michael S. Tsirkin, Parav Pandit and Jason Wang for their suggestions, it made below changes:
* Declared a new feature bit
* Add the description of conformance
* Improve it to virtio device level
* Change the unsuitable description, use "preserve resources" to replace "freeze mode" to avoid mixing with freeze. This patch is to protect all the resources that can't be re-create but we still need them, not to trigger any suspend or freeze behavior.

Best regards,
Jiqian Chen

v5:
makes below changes:
* Since this series patches add a new mechanism that let virtgpu and Qemu can negotiate their reset behavior, and other guys hope me can improve this mechanism to virtio pci level, so that other virtio devices can also benefit from it. So instead of adding new feature flag VIRTIO_GPU_F_FREEZE_S3 only serves for virtgpu, v5 add a new parameter named freeze_mode to struct virtio_pci_common_cfg, when guest begin suspending, set freeze_mode to VIRTIO_PCI_FREEZE_MODE_FREEZE_S3, and then all virtio devices can get this status, and notice that guest is suspending, then they can change their reset behavior.
V5 of Qemu patch:
https://lore.kernel.org/qemu-devel/[email protected]/T/#t
V5 of kernel patch:
https://lore.kernel.org/lkml/[email protected]/T/#t

v4:
no v4 patches.
V4 of Qemu patch:
https://lore.kernel.org/qemu-devel/[email protected]/T/#t
No v4 of kernel patch

v3:
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.
* Explain in more detail
Link:
https://lists.oasis-open.org/archives/virtio-comment/202307/msg00209.html
V3 of Qemu patch:
https://lore.kernel.org/qemu-devel/[email protected]
V3 of Kernel patch: https://lore.kernel.org/lkml/[email protected]/T/#t

v2:
makes below changes:
* Elaborate on the types of resources.
* Add some descriptions for S3 and S4.
Link:
https://lists.oasis-open.org/archives/virtio-comment/202307/msg00160.html
V2 of Qemu patch:
https://lore.kernel.org/qemu-devel/[email protected]/T/#t
V2 of Kernel patch:
https://lore.kernel.org/lkml/[email protected]/T/#t

v1:
Hi all,
I am working to implement virtgpu S3 function on Xen.

Currently on Xen, if we start a guest through Qemu with enabling virtgpu, and then suspend and s3resume guest. We can find that the guest kernel comes back, but the display doesn't. It just shown a black screen.

That is because when guest was during suspending, it called into Qemu and Qemu destroyed all resources and reset renderer. This made the display gone after guest resumed.

So, I add a mechanism that when guest is suspending, it will notify Qemu, and then Qemu will not destroy resources. That can help guest's display come back.

As discussed and suggested by Robert Beckett and Gerd Hoffmann on v1 qemu's mailing list.
Due to that mechanism needs cooperation between guest and host. What's more, as virtio drivers by design paravirt drivers, it is reasonable for guest to accept some cooperation with host to manage suspend/resume. So I request to add a new feature flag, so that guest and host can negotiate whenever freezing is supported or not. Link:
https://lists.oasis-open.org/archives/virtio-comment/202306/msg00595.html
V1 of Qemu patch:
https://lore.kernel.org/qemu-devel/[email protected]/
V1 of Kernel patch:
https://lore.kernel.org/lkml/[email protected]/

Jiqian Chen (1):
content: Add new feature VIRTIO_F_PRESERVE_RESOURCES

 conformance.tex   |  2 ++
 content.tex       | 25 +++++++++++++++++++++++++
 transport-pci.tex |  6 ++++++
 3 files changed, 33 insertions(+)
Signature · 18 lines
2.34.1


This publicly archived list offers a means to provide input to the
OASIS Virtual I/O Device (VIRTIO) TC.

In order to verify user consent to the Feedback License terms and
to minimize spam in the list archive, subscription is required
before posting.

Subscribe: [email protected]
Unsubscribe: [email protected]
List help: [email protected]
List archive: https://lists.oasis-open.org/archives/virtio-comment/
Feedback License: https://www.oasis-open.org/who/ipr/feedback_license.pdf
List Guidelines: https://www.oasis-open.org/policies-guidelines/mailing-lists
Committee: https://www.oasis-open.org/committees/virtio/
Join OASIS: https://www.oasis-open.org/join/
#1 lore raw

PATCH v6 1/1 content: Add new feature VIRTIO_F_PRESERVE_RESOURCES

In some scenes, Qemu may reset or destroy resources of virtio device, but some of them can't be re-created, so that causes some problems.

For example, when we do S3 for guest, guest will set device_status to 0, it causes Qemu to reset virtioi-gpu device, and then all render resources of virtio-gpu will be destroyed. As a result, after guest resuming, the display can't come back, and we only see a black screen.

In order to deal with the above scene, we need a mechanism that allows guest and Qemu to negotiate their behaviors for resources. So, this patch adds a new feature named VIRTIO_F_PRESERVE_RESOURCES. It allows guest to tell Qemu when there is a need to preserve resources, guest must preserve resources until 0 is set.

---
 conformance.tex   |  2 ++
 content.tex       | 25 +++++++++++++++++++++++++
 transport-pci.tex |  6 ++++++
 3 files changed, 33 insertions(+)
conformance.tex +2 -0
index dc00e84..60cc0b1 100644
@@ -91,6 +91,7 @@ \section{Conformance Targets}\label{sec:Conformance / Conformance Targets}
 \item \ref{drivernormative:Basic Facilities of a Virtio Device / Packed Virtqueues / The Virtqueue Descriptor Table / Indirect Descriptors}
 \item \ref{drivernormative:Basic Facilities of a Virtio Device / Packed Virtqueues / Supplying Buffers to The Device / Updating flags}
 \item \ref{drivernormative:Basic Facilities of a Virtio Device / Packed Virtqueues / Supplying Buffers to The Device / Sending Available Buffer Notifications}
+\item \ref{drivernormative:Basic Facilities of a Virtio Device / Preserve Resources}
 \item \ref{drivernormative:General Initialization And Device Operation / Device Initialization}
 \item \ref{drivernormative:General Initialization And Device Operation / Device Cleanup}
 \item \ref{drivernormative:Reserved Feature Bits}
@@ -172,6 +173,7 @@ \section{Conformance Targets}\label{sec:Conformance / Conformance Targets}
 \item \ref{devicenormative:Basic Facilities of a Virtio Device / Packed Virtqueues / The Virtqueue Descriptor Table}
 \item \ref{devicenormative:Basic Facilities of a Virtio Device / Packed Virtqueues / Scatter-Gather Support}
 \item \ref{devicenormative:Basic Facilities of a Virtio Device / Shared Memory Regions}
+\item \ref{devicenormative:Basic Facilities of a Virtio Device / Preserve Resources}
 \item \ref{devicenormative:Reserved Feature Bits}
 \end{itemize}
 
content.tex +25 -0
index 0a62dce..b6b1859 100644
@@ -502,6 +502,27 @@ \section{Exporting Objects}\label{sec:Basic Facilities of a Virtio Device / Expo
 types. It is RECOMMENDED that devices generate version 4
 UUIDs as specified by \hyperref[intro:rfc4122]{[RFC4122]}.
 
+\section{Preserve Resources}\label{sec:Basic Facilities of a Virtio Device / Preserve Resources}
+
+As virtio devices are paravirtualization devices by design.
+There are various devices resources created by sending commands
+from frontend and stored in backend.
+
+In some scenes, resources may be destroyed or reset, some of
+them can be re-created since frontend has enough information
+, but some can't. At this case, we can set \field{Preserve Resources}
+to 1 by specific transport, to prevent resources being destroyed.
+
+Which kind of resources need to be preserved and how to preserve
+resources depend on specific devices.
+
+\drivernormative{\subsection}{Preserve Resources}{Basic Facilities of a Virtio Device / Preserve resources}
+A driver SHOULD set \field{Preserve Resources} to 1 when there is a need
+to preserve resources.
+
+\devicenormative{\subsection}{Preserve Resources}{Basic Facilities of a Virtio Device / Preserve resources}
+A device MUST NOT destroy resources until \field{Preserve Resources} is 0.
+
 \input{admin.tex}
 
 \chapter{General Initialization And Device Operation}\label{sec:General Initialization And Device Operation}
@@ -872,6 +893,10 @@ \chapter{Reserved Feature Bits}\label{sec:Reserved Feature Bits}
 	\ref{devicenormative:Basic Facilities of a Virtio Device / Feature Bits} for
 	handling features reserved for future use.
 
+  \item[VIRTIO_F_PRESERVE_RESOURCES(42)] This feature indicates
+  that the device need to preserve resources.
+  See \ref{sec:Basic Facilities of a Virtio Device / Preserve Resources}.
+
 \end{description}
 
 \drivernormative{\section}{Reserved Feature Bits}{Reserved Feature Bits}
transport-pci.tex +6 -0
index a5c6719..f6eea65 100644
@@ -325,6 +325,7 @@ \subsubsection{Common configuration structure layout}\label{sec:Virtio Transport
         /* About the administration virtqueue. */
         le16 admin_queue_index;         /* read-only for driver */
         le16 admin_queue_num;         /* read-only for driver */
+        le16 preserve_resources;        /* read-write */
 };
 \end{lstlisting}
 
@@ -428,6 +429,11 @@ \subsubsection{Common configuration structure layout}\label{sec:Virtio Transport
 	The value 0 indicates no supported administration virtqueues.
 	This field is valid only if VIRTIO_F_ADMIN_VQ has been
 	negotiated.
+
+\item[\field{preserve_resources}]
+        The driver writes this to let device preserve resources whenever driver has demands.
+        1 - device need to preserve resources which can't be re-created, until 0 is set.
+        0 - all resources can be destroyed.
 \end{description}
 
 \devicenormative{\paragraph}{Common configuration structure layout}{Virtio Transport Options / Virtio Over PCI Bus / PCI Device Layout / Common configuration structure layout}
Signature · 6 lines
2.34.1


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
#2 lore raw

[virtio-comment] RE: [PATCH v6 1/1] content: Add new feature VIRTIO_F_PRESERVE_RESOURCES

Hi Jiqian,

Quoted 17 lines

From: Jiqian Chen <[email protected]>
Sent: Saturday, October 21, 2023 9:21 AM
To: Michael S . Tsirkin <[email protected]>; Gerd Hoffmann <[email protected]>; Parav Pandit <[email protected]>; Jason Wang <[email protected]>; Xuan Zhuo <[email protected]>; David Airlie <[email protected]>; Gurchetan Singh <[email protected]>; Chia-I Wu <[email protected]>; Marc- André Lureau <[email protected]>; Robert Beckett <[email protected]>; Mikhail Golubev-Ciuchea <Mikhail.Golubev- [email protected]>; [email protected]; virtio- [email protected]
Cc: Honglei Huang <[email protected]>; Julia Zhang <[email protected]>; Huang Rui <[email protected]>; Jiqian Chen <[email protected]>
Subject: [PATCH v6 1/1] content: Add new feature VIRTIO_F_PRESERVE_RESOURCES

Quoted 3 lines

In some scenes, Qemu may reset or destroy resources of virtio device, but some of them can't be re-created, so that causes some problems.

It can be re-created. It is just that the guest driver lost the previous resource values. So a better wording for the motivation is combining with below line to me is,

Currently guest drivers destroy and re-create virtio resources during power management suspend/resume sequence respectively. For example, for a PCI transport, even if the device offers D3 to d0 state transition, a virtio guest driver has no way to know if the device can store the state during D0->D3 transition and same state can be restored on D3->D0 transition.

Quoted 5 lines

For example, when we do S3 for guest, guest will set device_status to 0, it causes Qemu to reset virtioi-gpu device, and then all render resources of virtio- gpu will be destroyed. As a result, after guest resuming, the display can't come back, and we only see a black screen.

To make guest drivers aware of above device capability, introduce a new feature bit to indicate such device capability. This patch adds...

Quoted 6 lines

In order to deal with the above scene, we need a mechanism that allows guest and Qemu to negotiate their behaviors for resources. So, this patch adds a new feature named VIRTIO_F_PRESERVE_RESOURCES. It allows guest to tell Qemu when there is a need to preserve resources, guest must preserve resources until 0 is set.

I think this can be done without introducing the new register.
Can you please check if the PM register itself can serve the purpose instead of new virtio level register?

Quoted 43 lines
---
 conformance.tex   |  2 ++
 content.tex       | 25 +++++++++++++++++++++++++
 transport-pci.tex |  6 ++++++
 3 files changed, 33 insertions(+)
conformance.tex index dc00e84..60cc0b1 renamed from conformance.tex +0 -0

100644

conformance.tex +0 -0
@@ -91,6 +91,7 @@ \section{Conformance Targets}\label{sec:Conformance /

Conformance Targets} \item \ref{drivernormative:Basic Facilities of a Virtio Device / Packed Virtqueues / The Virtqueue Descriptor Table / Indirect Descriptors} \item \ref{drivernormative:Basic Facilities of a Virtio Device / Packed Virtqueues / Supplying Buffers to The Device / Updating flags} \item \ref{drivernormative:Basic Facilities of a Virtio Device / Packed Virtqueues / Supplying Buffers to The Device / Sending Available Buffer Notifications} +\item \ref{drivernormative:Basic Facilities of a Virtio Device / +Preserve Resources}
\item \ref{drivernormative:General Initialization And Device Operation /
Device Initialization} \item \ref{drivernormative:General Initialization And Device Operation / Device Cleanup} \item \ref{drivernormative:Reserved Feature Bits} @@ -172,6 +173,7 @@ \section{Conformance Targets}\label{sec:Conformance / Conformance Targets} \item \ref{devicenormative:Basic Facilities of a Virtio Device / Packed Virtqueues / The Virtqueue Descriptor Table} \item \ref{devicenormative:Basic Facilities of a Virtio Device / Packed Virtqueues / Scatter-Gather Support} \item \ref{devicenormative:Basic Facilities of a Virtio Device / Shared Memory Regions}
+\item \ref{devicenormative:Basic Facilities of a Virtio Device /

conformance.tex +1 -0
+Preserve Resources}
 \item \ref{devicenormative:Reserved Feature Bits}  \end{itemize}
content.tex +0 -0
index 0a62dce..b6b1859 100644
@@ -502,6 +502,27 @@ \section{Exporting Objects}\label{sec:Basic Facilities

of a Virtio Device / Expo types. It is RECOMMENDED that devices generate version 4 UUIDs as specified by \hyperref[intro:rfc4122]{[RFC4122]}.

+\section{Preserve Resources}\label{sec:Basic Facilities of a Virtio

content.tex \section{Exporting Objects}\label{sec:Basic Facilities of a Virtio Device / Expo · line 507

Quoted 3 lines
content.tex +3 -0
+Device / Preserve Resources}
+
+As virtio devices are paravirtualization devices by design.

This is not true and not relevant for the spec. Please remove this line.

content.tex

Quoted 10 lines
content.tex +10 -0
+There are various devices resources created by sending commands from
+frontend and stored in backend.
+
+In some scenes, resources may be destroyed or reset, some of them can
+be re-created since frontend has enough information , but some can't.
+At this case, we can set \field{Preserve Resources} to 1 by specific
+transport, to prevent resources being destroyed.
+
+Which kind of resources need to be preserved and how to preserve
+resources depend on specific devices.

s/on specific devices/on specific device type/

Quoted 29 lines
content.tex +7 -0
+
+\drivernormative{\subsection}{Preserve Resources}{Basic Facilities of a
+Virtio Device / Preserve resources} A driver SHOULD set \field{Preserve
+Resources} to 1 when there is a need to preserve resources.
+
+\devicenormative{\subsection}{Preserve Resources}{Basic Facilities of a
+Virtio Device / Preserve resources} A device MUST NOT destroy resources until

\field{Preserve Resources} is 0.
+
\input{admin.tex}

\chapter{General Initialization And Device Operation}\label{sec:General
Initialization And Device Operation} @@ -872,6 +893,10 @@ \chapter{Reserved Feature Bits}\label{sec:Reserved Feature Bits}
\ref{devicenormative:Basic Facilities of a Virtio Device / Feature Bits}
for

content.tex +4 -0
 	handling features reserved for future use.
 
+  \item[VIRTIO_F_PRESERVE_RESOURCES(42)] This feature indicates  that
+ the device need to preserve resources.
+  See \ref{sec:Basic Facilities of a Virtio Device / Preserve Resources}.
+
 \end{description}
 
 \drivernormative{\section}{Reserved Feature Bits}{Reserved Feature Bits} diff --

git a/transport-pci.tex b/transport-pci.tex index a5c6719..f6eea65 100644

transport-pci.tex +0 -0
@@ -325,6 +325,7 @@ \subsubsection{Common configuration structure
Quoted 5 lines

layout}\label{sec:Virtio Transport
/* About the administration virtqueue. */
le16 admin_queue_index; /* read-only for driver */
le16 admin_queue_num; /* read-only for driver */
+ le16 preserve_resources; /* read-write */

Preserving these resources in the device implementation takes finite amount of time.
Possibly more than 40nsec (time of PCIe write TLP).
Hence this register must be a polling register to indicate that preservation_done.
This will tell the guest when the preservation is done, and when restoration is done, so that it can resume upper layers.

Please refer to queue_reset definition to learn more about such register definition.

Lets please make sure that PCIe PM level registers are sufficient/not-sufficient to decide the addition of this register.

Quoted 17 lines

};
\end{lstlisting}

transport-pci.tex +0 -0
@@ -428,6 +429,11 @@ \subsubsection{Common configuration structure

layout}\label{sec:Virtio Transport

transport-pci.tex +3 -0
 	The value 0 indicates no supported administration virtqueues.
 	This field is valid only if VIRTIO_F_ADMIN_VQ has been
 	negotiated.
+
+\item[\field{preserve_resources}]
+        The driver writes this to let device preserve resources whenever driver

has demands.
+ 1 - device need to preserve resources which can't be re-created, until 0 is
set.
+ 0 - all resources can be destroyed.
\end{description}

Quoted 5 lines

\devicenormative{\paragraph}{Common configuration structure layout}{Virtio
Transport Options / Virtio Over PCI Bus / PCI Device Layout / Common configuration structure layout}
--
2.34.1

This publicly archived list offers a means to provide input to the OASIS Virtual I/O Device (VIRTIO) TC.

In order to verify user consent to the Feedback License terms and to minimize spam in the list archive, subscription is required before posting.

Subscribe: [email protected]
Unsubscribe: [email protected]
List help: [email protected]
List archive: https://lists.oasis-open.org/archives/virtio-comment/
Feedback License: https://www.oasis-open.org/who/ipr/feedback_license.pdf
List Guidelines: https://www.oasis-open.org/policies-guidelines/mailing-lists
Committee: https://www.oasis-open.org/committees/virtio/
Join OASIS: https://www.oasis-open.org/join/

#3 lore raw

[virtio-comment] Re: [PATCH v6 1/1] content: Add new feature VIRTIO_F_PRESERVE_RESOURCES

Quoted 19 lines · Parav Pandit

Hi Jiqian,

Quoted 17 lines

From: Jiqian Chen <[email protected]>
Sent: Saturday, October 21, 2023 9:21 AM
To: Michael S . Tsirkin <[email protected]>; Gerd Hoffmann <[email protected]>; Parav Pandit <[email protected]>; Jason Wang <[email protected]>; Xuan Zhuo <[email protected]>; David Airlie <[email protected]>; Gurchetan Singh <[email protected]>; Chia-I Wu <[email protected]>; Marc- André Lureau <[email protected]>; Robert Beckett <[email protected]>; Mikhail Golubev-Ciuchea <Mikhail.Golubev- [email protected]>; [email protected]; virtio- [email protected]
Cc: Honglei Huang <[email protected]>; Julia Zhang <[email protected]>; Huang Rui <[email protected]>; Jiqian Chen <[email protected]>
Subject: [PATCH v6 1/1] content: Add new feature VIRTIO_F_PRESERVE_RESOURCES

Quoted 5 lines
Quoted 3 lines

In some scenes, Qemu may reset or destroy resources of virtio device, but some of them can't be re-created, so that causes some problems.

It can be re-created. It is just that the guest driver lost the previous resource values. So a better wording for the motivation is combining with below line to me is,

Yes, guest driver hasn't enough information or values of resources to re-create them. I will change my description in next version.

Quoted 4 lines

Currently guest drivers destroy and re-create virtio resources during power management suspend/resume sequence respectively. For example, for a PCI transport, even if the device offers D3 to d0 state transition, a virtio guest driver has no way to know if the device can store the state during D0->D3 transition and same state can be restored on D3->D0 transition.

Thanks, will change in next version.

Quoted 8 lines
Quoted 6 lines

For example, when we do S3 for guest, guest will set device_status to 0, it causes Qemu to reset virtioi-gpu device, and then all render resources of virtio- gpu will be destroyed. As a result, after guest resuming, the display can't come back, and we only see a black screen.

To make guest drivers aware of above device capability, introduce a new feature bit to indicate such device capability. This patch adds...

Thanks, will change in next version.

Quoted 9 lines
Quoted 7 lines

In order to deal with the above scene, we need a mechanism that allows guest and Qemu to negotiate their behaviors for resources. So, this patch adds a new feature named VIRTIO_F_PRESERVE_RESOURCES. It allows guest to tell Qemu when there is a need to preserve resources, guest must preserve resources until 0 is set.

I think this can be done without introducing the new register.
Can you please check if the PM register itself can serve the purpose instead of new virtio level register?

Do you mean the system PM register? I think it is unreasonable to let virtio-device listen the PM state of Guest system. It's more suitable that each device gets notifications from driver, and then do preserving resources operation.

Quoted 43 lines
Quoted 43 lines
---
 conformance.tex   |  2 ++
 content.tex       | 25 +++++++++++++++++++++++++
 transport-pci.tex |  6 ++++++
 3 files changed, 33 insertions(+)
conformance.tex index dc00e84..60cc0b1 renamed from conformance.tex +0 -0

100644

conformance.tex +0 -0
@@ -91,6 +91,7 @@ \section{Conformance Targets}\label{sec:Conformance /

Conformance Targets} \item \ref{drivernormative:Basic Facilities of a Virtio Device / Packed Virtqueues / The Virtqueue Descriptor Table / Indirect Descriptors} \item \ref{drivernormative:Basic Facilities of a Virtio Device / Packed Virtqueues / Supplying Buffers to The Device / Updating flags} \item \ref{drivernormative:Basic Facilities of a Virtio Device / Packed Virtqueues / Supplying Buffers to The Device / Sending Available Buffer Notifications} +\item \ref{drivernormative:Basic Facilities of a Virtio Device / +Preserve Resources}
\item \ref{drivernormative:General Initialization And Device Operation /
Device Initialization} \item \ref{drivernormative:General Initialization And Device Operation / Device Cleanup} \item \ref{drivernormative:Reserved Feature Bits} @@ -172,6 +173,7 @@ \section{Conformance Targets}\label{sec:Conformance / Conformance Targets} \item \ref{devicenormative:Basic Facilities of a Virtio Device / Packed Virtqueues / The Virtqueue Descriptor Table} \item \ref{devicenormative:Basic Facilities of a Virtio Device / Packed Virtqueues / Scatter-Gather Support} \item \ref{devicenormative:Basic Facilities of a Virtio Device / Shared Memory Regions}
+\item \ref{devicenormative:Basic Facilities of a Virtio Device /

conformance.tex +1 -0
+Preserve Resources}
 \item \ref{devicenormative:Reserved Feature Bits}  \end{itemize}
content.tex +0 -0
index 0a62dce..b6b1859 100644
@@ -502,6 +502,27 @@ \section{Exporting Objects}\label{sec:Basic Facilities

of a Virtio Device / Expo types. It is RECOMMENDED that devices generate version 4 UUIDs as specified by \hyperref[intro:rfc4122]{[RFC4122]}.

Quoted 5 lines

content.tex \section{Exporting Objects}\label{sec:Basic Facilities of a Virtio Device / Expo · line 507

Quoted 4 lines

+\section{Preserve Resources}\label{sec:Basic Facilities of a Virtio

content.tex +3 -0
+Device / Preserve Resources}
+
+As virtio devices are paravirtualization devices by design.

This is not true and not relevant for the spec. Please remove this line.

OK, will remove this line in next version.

Quoted 12 lines

content.tex

Quoted 11 lines
content.tex +10 -0
+There are various devices resources created by sending commands from
+frontend and stored in backend.
+
+In some scenes, resources may be destroyed or reset, some of them can
+be re-created since frontend has enough information , but some can't.
+At this case, we can set \field{Preserve Resources} to 1 by specific
+transport, to prevent resources being destroyed.
+
+Which kind of resources need to be preserved and how to preserve
+resources depend on specific devices.

s/on specific devices/on specific device type/

Thanks, will change in next version.

Quoted 40 lines
Quoted 30 lines
content.tex +7 -0
+
+\drivernormative{\subsection}{Preserve Resources}{Basic Facilities of a
+Virtio Device / Preserve resources} A driver SHOULD set \field{Preserve
+Resources} to 1 when there is a need to preserve resources.
+
+\devicenormative{\subsection}{Preserve Resources}{Basic Facilities of a
+Virtio Device / Preserve resources} A device MUST NOT destroy resources until

\field{Preserve Resources} is 0.
+
\input{admin.tex}

\chapter{General Initialization And Device Operation}\label{sec:General
Initialization And Device Operation} @@ -872,6 +893,10 @@ \chapter{Reserved Feature Bits}\label{sec:Reserved Feature Bits}
\ref{devicenormative:Basic Facilities of a Virtio Device / Feature Bits}
for

content.tex +4 -0
 	handling features reserved for future use.
 
+  \item[VIRTIO_F_PRESERVE_RESOURCES(42)] This feature indicates  that
+ the device need to preserve resources.
+  See \ref{sec:Basic Facilities of a Virtio Device / Preserve Resources}.
+
 \end{description}
 
 \drivernormative{\section}{Reserved Feature Bits}{Reserved Feature Bits} diff --

git a/transport-pci.tex b/transport-pci.tex index a5c6719..f6eea65 100644

transport-pci.tex +0 -0
@@ -325,6 +325,7 @@ \subsubsection{Common configuration structure
Quoted 5 lines

layout}\label{sec:Virtio Transport
/* About the administration virtqueue. */
le16 admin_queue_index; /* read-only for driver */
le16 admin_queue_num; /* read-only for driver */
+ le16 preserve_resources; /* read-write */

Preserving these resources in the device implementation takes finite amount of time.
Possibly more than 40nsec (time of PCIe write TLP).
Hence this register must be a polling register to indicate that preservation_done.
This will tell the guest when the preservation is done, and when restoration is done, so that it can resume upper layers.

Quoted 1 line

Please refer to queue_reset definition to learn more about such register definition.

Thanks, I will refer to "queue_reset". So, I need three values, driver write 1 to let device do preserving resources, driver write 2 to let device do restoring resources, device write 0 to tell driver that preserving or restoring done, am I right?

Quoted 2 lines

Lets please make sure that PCIe PM level registers are sufficient/not-sufficient to decide the addition of this register.

But if the device is not a PCIe device, it doesn't have PM capability, then this will not work. Actually in my local environment, pci_is_express() return false in Qemu, they are not PCIe device.

Quoted 24 lines
Quoted 23 lines

};
\end{lstlisting}

transport-pci.tex +0 -0
@@ -428,6 +429,11 @@ \subsubsection{Common configuration structure

layout}\label{sec:Virtio Transport

transport-pci.tex +3 -0
 	The value 0 indicates no supported administration virtqueues.
 	This field is valid only if VIRTIO_F_ADMIN_VQ has been
 	negotiated.
+
+\item[\field{preserve_resources}]
+        The driver writes this to let device preserve resources whenever driver

has demands.
+ 1 - device need to preserve resources which can't be re-created, until 0 is
set.
+ 0 - all resources can be destroyed.
\end{description}

\devicenormative{\paragraph}{Common configuration structure layout}{Virtio
Transport Options / Virtio Over PCI Bus / PCI Device Layout / Common configuration structure layout}
--
2.34.1

Signature · 2 lines
Best regards,
Jiqian Chen.
#4 lore raw

[virtio-comment] RE: [PATCH v6 1/1] content: Add new feature VIRTIO_F_PRESERVE_RESOURCES

Quoted 8 lines

From: Chen, Jiqian <[email protected]>
Sent: Monday, October 23, 2023 4:09 PM

Quoted 2 lines

I think this can be done without introducing the new register. Can you please check if the PM register itself can serve the purpose instead

of new virtio level register?
Do you mean the system PM register?

No, the device's PM register at transport level.

Quoted 2 lines

I think it is unreasonable to let virtio-
device listen the PM state of Guest system.

Guest driver performs any work on the guest systems PM callback events in the virtio driver.

Quoted 2 lines

It's more suitable that each device
gets notifications from driver, and then do preserving resources operation.

I agree that each device gets the notification from driver.
The question is, should it be virtio driver, or existing pci driver which transitions the state from d0->d3 and d3->d0 is enough. Can you please check that?

Quoted 14 lines
Quoted 9 lines
Quoted 8 lines
transport-pci.tex +0 -0
@@ -325,6 +325,7 @@ \subsubsection{Common configuration structure

layout}\label{sec:Virtio Transport
/* About the administration virtqueue. */
le16 admin_queue_index; /* read-only for driver */
le16 admin_queue_num; /* read-only for driver */
+ le16 preserve_resources; /* read-write */

Preserving these resources in the device implementation takes finite amount

of time.

Quoted 2 lines

Possibly more than 40nsec (time of PCIe write TLP). Hence this register must be a polling register to indicate that

preservation_done.

Quoted 1 line

This will tell the guest when the preservation is done, and when restoration is

Quoted 9 lines

done, so that it can resume upper layers.

Quoted 2 lines

Please refer to queue_reset definition to learn more about such register

definition.
Thanks, I will refer to "queue_reset". So, I need three values, driver write 1 to let device do preserving resources, driver write 2 to let device do restoring resources, device write 0 to tell driver that preserving or restoring done, am I right?

Right.

And if the existing pcie pm state bits can do, we can leverage that.
If it cannot be used, lets add that reasoning in the commit log to describe this register.

Quoted 6 lines
Quoted 2 lines

Lets please make sure that PCIe PM level registers are sufficient/not-sufficient

to decide the addition of this register.
But if the device is not a PCIe device, it doesn't have PM capability, then this will not work. Actually in my local environment, pci_is_express() return false in Qemu, they are not PCIe device.

It is reasonable to ask to plug in as PCIe device in 2023 to get new functionality that too you mentioned a gpu device. 😊 Which does not have very long history of any backward compatibility.
Please explore the d0<->d3 PM state bit if can be used.

Thanks a lot.

#5 lore raw

[virtio-comment] Re: [PATCH v6 1/1] content: Add new feature VIRTIO_F_PRESERVE_RESOURCES

Quoted 9 lines · Parav Pandit
Quoted 8 lines

From: Chen, Jiqian <[email protected]>
Sent: Monday, October 23, 2023 4:09 PM

Quoted 2 lines

I think this can be done without introducing the new register. Can you please check if the PM register itself can serve the purpose instead

of new virtio level register?
Do you mean the system PM register?

No, the device's PM register at transport level.

I tried to find this register(pci level or virtio pci level or virtio driver level), but I didn't find it in Linux kernel or Qemu codes. May I know which register you are referring to specifically? Or which PM state bit you mentioned below?

Quoted 4 lines
Quoted 3 lines

I think it is unreasonable to let virtio-
device listen the PM state of Guest system.

Guest driver performs any work on the guest systems PM callback events in the virtio driver.

I didn't find any PM state callback in the virtio driver.

Quoted 5 lines
Quoted 3 lines

It's more suitable that each device
gets notifications from driver, and then do preserving resources operation.

I agree that each device gets the notification from driver.
The question is, should it be virtio driver, or existing pci driver which transitions the state from d0->d3 and d3->d0 is enough.

It seems there isn't existing pci driver to transitions d0 or d3 state. Could you please tell me which one it is specifically? I am very willing to give a try.

Quoted 31 lines

Can you please check that?

Quoted 14 lines
Quoted 9 lines
Quoted 8 lines
transport-pci.tex +0 -0
@@ -325,6 +325,7 @@ \subsubsection{Common configuration structure

layout}\label{sec:Virtio Transport
/* About the administration virtqueue. */
le16 admin_queue_index; /* read-only for driver */
le16 admin_queue_num; /* read-only for driver */
+ le16 preserve_resources; /* read-write */

Preserving these resources in the device implementation takes finite amount

of time.

Quoted 2 lines

Possibly more than 40nsec (time of PCIe write TLP). Hence this register must be a polling register to indicate that

preservation_done.

Quoted 1 line

This will tell the guest when the preservation is done, and when restoration is

Quoted 9 lines

done, so that it can resume upper layers.

Quoted 2 lines

Please refer to queue_reset definition to learn more about such register

definition.
Thanks, I will refer to "queue_reset". So, I need three values, driver write 1 to let device do preserving resources, driver write 2 to let device do restoring resources, device write 0 to tell driver that preserving or restoring done, am I right?

Right.

And if the existing pcie pm state bits can do, we can leverage that.
If it cannot be used, lets add that reasoning in the commit log to describe this register.

Quoted 1 line
Quoted 1 line
Quoted 7 lines
Quoted 5 lines
Quoted 1 line

Lets please make sure that PCIe PM level registers are sufficient/not-sufficient

to decide the addition of this register.
But if the device is not a PCIe device, it doesn't have PM capability, then this will not work. Actually in my local environment, pci_is_express() return false in Qemu, they are not PCIe device.

It is reasonable to ask to plug in as PCIe device in 2023 to get new functionality that too you mentioned a gpu device. 😊 Which does not have very long history of any backward compatibility.

Do you suggest me to add PM capability for virtio-gpu or change virtio-gpu to a PCIe device?

Quoted 3 lines

Please explore the d0<->d3 PM state bit if can be used.

Thanks a lot.

Signature · 2 lines
Best regards,
Jiqian Chen.
#6 lore raw

[virtio-comment] RE: [PATCH v6 1/1] content: Add new feature VIRTIO_F_PRESERVE_RESOURCES

Quoted 12 lines

From: Chen, Jiqian <[email protected]>
Sent: Tuesday, October 24, 2023 4:06 PM

Quoted 7 lines · Parav Pandit
Quoted 7 lines

From: Chen, Jiqian <[email protected]>
Sent: Monday, October 23, 2023 4:09 PM

Quoted 3 lines

I think this can be done without introducing the new register. Can you please check if the PM register itself can serve the purpose instead

Quoted 8 lines
Quoted 3 lines
Quoted 2 lines

of new virtio level register?
Do you mean the system PM register?

No, the device's PM register at transport level.

I tried to find this register(pci level or virtio pci level or virtio driver level), but I didn't find it in Linux kernel or Qemu codes.
May I know which register you are referring to specifically? Or which PM state bit you mentioned below?

PCI spec's PCI Power Management Capability Structure in section 7.5.2.

Quoted 7 lines
Quoted 4 lines
Quoted 3 lines

I think it is unreasonable to let virtio- device listen the PM state of Guest system.

Guest driver performs any work on the guest systems PM callback events in

the virtio driver.
I didn't find any PM state callback in the virtio driver.

There are virtio_suspend and virtio_resume in case of Linux.

Quoted 9 lines
Quoted 5 lines
Quoted 3 lines

It's more suitable that each device
gets notifications from driver, and then do preserving resources operation.

I agree that each device gets the notification from driver. The question is, should it be virtio driver, or existing pci driver which

transitions the state from d0->d3 and d3->d0 is enough.
It seems there isn't existing pci driver to transitions d0 or d3 state. Could you please tell me which one it is specifically? I am very willing to give a try.

Virtio-pci modern driver of Linux should be able to.

Quoted 41 lines
Quoted 28 lines

Can you please check that?

Quoted 18 lines
Quoted 10 lines
Quoted 8 lines
transport-pci.tex +0 -0
@@ -325,6 +325,7 @@ \subsubsection{Common configuration structure

layout}\label{sec:Virtio Transport
/* About the administration virtqueue. */
le16 admin_queue_index; /* read-only for driver */
le16 admin_queue_num; /* read-only for driver */
+ le16 preserve_resources; /* read-write */

Preserving these resources in the device implementation takes finite amount

of time.

Quoted 2 lines

Possibly more than 40nsec (time of PCIe write TLP). Hence this register must be a polling register to indicate that

preservation_done.

Quoted 2 lines

This will tell the guest when the preservation is done, and when restoration is

done, so that it can resume upper layers.

Quoted 1 line
Quoted 8 lines
Quoted 2 lines

Please refer to queue_reset definition to learn more about such register

definition.
Thanks, I will refer to "queue_reset". So, I need three values, driver write 1 to let device do preserving resources, driver write 2 to let device do restoring resources, device write 0 to tell driver that preserving or restoring done, am I right?

Quoted 4 lines

Right.

And if the existing pcie pm state bits can do, we can leverage that. If it cannot be used, lets add that reasoning in the commit log to describe this

register.

Quoted 8 lines
Quoted 8 lines
Quoted 4 lines

Lets please make sure that PCIe PM level registers are sufficient/not-sufficient

to decide the addition of this register.
But if the device is not a PCIe device, it doesn't have PM capability, then this will not work. Actually in my local environment, pci_is_express() return false in Qemu, they are not PCIe

Quoted 7 lines

device.

Quoted 3 lines

It is reasonable to ask to plug in as PCIe device in 2023 to get new functionality that too you mentioned a gpu device. 😊 Which does not have very long history of any backward compatibility.

Do you suggest me to add PM capability for virtio-gpu or change virtio-gpu to a PCIe device?

PCI Power Management Capability Structure does not seem to be limited to PCIe.

#7 lore raw

[virtio-comment] Re: [PATCH v6 1/1] content: Add new feature VIRTIO_F_PRESERVE_RESOURCES

Quoted 14 lines · Parav Pandit
Quoted 14 lines

From: Chen, Jiqian <[email protected]>
Sent: Tuesday, October 24, 2023 4:06 PM

Quoted 9 lines · Parav Pandit
Quoted 9 lines

From: Chen, Jiqian <[email protected]>
Sent: Monday, October 23, 2023 4:09 PM

Quoted 3 lines

I think this can be done without introducing the new register. Can you please check if the PM register itself can serve the purpose instead

of new virtio level register?
Do you mean the system PM register?

Quoted 7 lines
Quoted 6 lines
Quoted 1 line

No, the device's PM register at transport level.

I tried to find this register(pci level or virtio pci level or virtio driver level), but I didn't find it in Linux kernel or Qemu codes.
May I know which register you are referring to specifically? Or which PM state bit you mentioned below?

PCI spec's PCI Power Management Capability Structure in section 7.5.2.

Yes, what you point to is PM capability for PCIe device.
But the problem is still that in Qemu code, it will check the condition(pci_bus_is_express or pci_is_express) of all virtio-pci devices in function virtio_pci_realize(), if the virtio devices aren't a PCIe device, it will not add PM capability for them. And another problem is how about the MMIO transport devices? Since preserve resources is need for all transport type devices.

Quoted 8 lines
Quoted 7 lines
Quoted 4 lines
Quoted 3 lines

I think it is unreasonable to let virtio- device listen the PM state of Guest system.

Guest driver performs any work on the guest systems PM callback events in

the virtio driver.
I didn't find any PM state callback in the virtio driver.

There are virtio_suspend and virtio_resume in case of Linux.

I think what you said virtio_suspend/resume is freeze/restore callback from "struct virtio_driver" or suspend/resume callback from "static const struct dev_pm_ops virtio_pci_pm_ops". And yes, I agree, if virtio devices have PM capability, maybe we can set PM state in those callback functions.

Quoted 11 lines
Quoted 10 lines
Quoted 6 lines
Quoted 4 lines

It's more suitable that each device
gets notifications from driver, and then do preserving resources operation.

I agree that each device gets the notification from driver. The question is, should it be virtio driver, or existing pci driver which

transitions the state from d0->d3 and d3->d0 is enough.
It seems there isn't existing pci driver to transitions d0 or d3 state. Could you please tell me which one it is specifically? I am very willing to give a try.

Virtio-pci modern driver of Linux should be able to.

Yes, I know, it is the VIRTIO_PCI_FLAG_INIT_PM_BIT. But still the two problems I said above.

Quoted 42 lines
Quoted 42 lines
Quoted 29 lines

Can you please check that?

Quoted 18 lines
Quoted 10 lines
Quoted 8 lines
transport-pci.tex +0 -0
@@ -325,6 +325,7 @@ \subsubsection{Common configuration structure

layout}\label{sec:Virtio Transport
/* About the administration virtqueue. */
le16 admin_queue_index; /* read-only for driver */
le16 admin_queue_num; /* read-only for driver */
+ le16 preserve_resources; /* read-write */

Preserving these resources in the device implementation takes finite amount

of time.

Quoted 2 lines

Possibly more than 40nsec (time of PCIe write TLP). Hence this register must be a polling register to indicate that

preservation_done.

Quoted 2 lines

This will tell the guest when the preservation is done, and when restoration is

done, so that it can resume upper layers.

Quoted 1 line
Quoted 8 lines
Quoted 2 lines

Please refer to queue_reset definition to learn more about such register

definition.
Thanks, I will refer to "queue_reset". So, I need three values, driver write 1 to let device do preserving resources, driver write 2 to let device do restoring resources, device write 0 to tell driver that preserving or restoring done, am I right?

Quoted 4 lines

Right.

And if the existing pcie pm state bits can do, we can leverage that. If it cannot be used, lets add that reasoning in the commit log to describe this

register.

Quoted 8 lines
Quoted 8 lines
Quoted 4 lines

Lets please make sure that PCIe PM level registers are sufficient/not-sufficient

to decide the addition of this register.
But if the device is not a PCIe device, it doesn't have PM capability, then this will not work. Actually in my local environment, pci_is_express() return false in Qemu, they are not PCIe

Quoted 8 lines
Quoted 7 lines

device.

Quoted 3 lines

It is reasonable to ask to plug in as PCIe device in 2023 to get new functionality that too you mentioned a gpu device. 😊 Which does not have very long history of any backward compatibility.

Do you suggest me to add PM capability for virtio-gpu or change virtio-gpu to a PCIe device?

PCI Power Management Capability Structure does not seem to be limited to PCIe.

I am not sure, but in current Qemu code, I can see the check "pci_is_express" for all virtio-pci devices. If we want to add PM capability for virtio-pci devices, we need to change them to PCIe device I think.

Quoted 1 line
Signature · 2 lines
Best regards,
Jiqian Chen.
#8 lore raw

[virtio-comment] RE: [PATCH v6 1/1] content: Add new feature VIRTIO_F_PRESERVE_RESOURCES

Quoted 26 lines

From: Chen, Jiqian <[email protected]>
Sent: Tuesday, October 24, 2023 5:44 PM

Quoted 20 lines · Parav Pandit
Quoted 20 lines

From: Chen, Jiqian <[email protected]>
Sent: Tuesday, October 24, 2023 4:06 PM

Quoted 10 lines · Parav Pandit
Quoted 9 lines

From: Chen, Jiqian <[email protected]>
Sent: Monday, October 23, 2023 4:09 PM

Quoted 3 lines

I think this can be done without introducing the new register. Can you please check if the PM register itself can serve the purpose instead

of new virtio level register?
Do you mean the system PM register?

No, the device's PM register at transport level.

I tried to find this register(pci level or virtio pci level or virtio driver level), but I didn't find it in Linux kernel or Qemu codes. May I know which register you are referring to specifically? Or which PM state bit you mentioned below?

Quoted 6 lines
Quoted 1 line

PCI spec's PCI Power Management Capability Structure in section 7.5.2.

Yes, what you point to is PM capability for PCIe device.
But the problem is still that in Qemu code, it will check the condition(pci_bus_is_express or pci_is_express) of all virtio-pci devices in function virtio_pci_realize(), if the virtio devices aren't a PCIe device, it will not add PM capability for them.

PCI PM capability is must for PCIe devices. So may be QEMU code has put it only under is_pcie check.
But it can be done outside of that check as well because this capability exists on PCI too for long time and it is backward compatible.

Quoted 3 lines

And another problem is how about the MMIO transport devices? Since preserve resources is need for all transport type devices.

MMIO lacks such rich PM definitions. If in future MMIO wants to support, it will be extended to match to other transports like PCI.

Quoted 22 lines
Quoted 9 lines
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

I think it is unreasonable to let virtio- device listen the PM state of Guest system.

Guest driver performs any work on the guest systems PM callback events in

the virtio driver.
I didn't find any PM state callback in the virtio driver.

There are virtio_suspend and virtio_resume in case of Linux.

I think what you said virtio_suspend/resume is freeze/restore callback from "struct virtio_driver" or suspend/resume callback from "static const struct dev_pm_ops virtio_pci_pm_ops".
And yes, I agree, if virtio devices have PM capability, maybe we can set PM state in those callback functions.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines

It's more suitable that each device gets notifications from driver, and then do preserving resources operation.

I agree that each device gets the notification from driver. The question is, should it be virtio driver, or existing pci driver which

Quoted 9 lines
Quoted 3 lines
Quoted 3 lines

transitions the state from d0->d3 and d3->d0 is enough.
It seems there isn't existing pci driver to transitions d0 or d3 state. Could you please tell me which one it is specifically? I am very willing to

give a try.

Quoted 2 lines
Quoted 1 line

Virtio-pci modern driver of Linux should be able to.

Yes, I know, it is the VIRTIO_PCI_FLAG_INIT_PM_BIT. But still the two problems I said above.

Both can be resolved without switching to pcie.

Quoted 49 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

Can you please check that?

Quoted 3 lines
Quoted 3 lines

transport-pci.tex \subsubsection{Common configuration

Quoted 3 lines
transport-pci.tex +0 -0
@@ -325,6 +325,7 @@ \subsubsection{Common configuration

structure

Quoted 42 lines
Quoted 42 lines
Quoted 23 lines
Quoted 15 lines
Quoted 7 lines
Quoted 5 lines

layout}\label{sec:Virtio Transport
/* About the administration virtqueue. */
le16 admin_queue_index; /* read-only for driver */
le16 admin_queue_num; /* read-only for driver */
+ le16 preserve_resources; /* read-write */

Preserving these resources in the device implementation takes finite amount

of time.

Quoted 2 lines

Possibly more than 40nsec (time of PCIe write TLP). Hence this register must be a polling register to indicate that

preservation_done.

Quoted 2 lines

This will tell the guest when the preservation is done, and when restoration is

done, so that it can resume upper layers.

Quoted 1 line
Quoted 8 lines
Quoted 2 lines

Please refer to queue_reset definition to learn more about such register

definition.
Thanks, I will refer to "queue_reset". So, I need three values, driver write 1 to let device do preserving resources, driver write 2 to let device do restoring resources, device write 0 to tell driver that preserving or restoring done, am I right?

Quoted 5 lines

Right.

And if the existing pcie pm state bits can do, we can leverage that. If it cannot be used, lets add that reasoning in the commit log to describe this

register.

Quoted 9 lines
Quoted 9 lines
Quoted 4 lines

Lets please make sure that PCIe PM level registers are sufficient/not-sufficient

to decide the addition of this register.
But if the device is not a PCIe device, it doesn't have PM capability, then this will not work. Actually in my local environment, pci_is_express() return false in Qemu, they are not PCIe

device.

Quoted 3 lines

It is reasonable to ask to plug in as PCIe device in 2023 to get new functionality that too you mentioned a gpu device. 😊 Which does not have very long history of any backward compatibility.

Quoted 9 lines
Quoted 4 lines
Quoted 3 lines

Do you suggest me to add PM capability for virtio-gpu or change virtio-gpu to a PCIe device?

PCI Power Management Capability Structure does not seem to be limited to

PCIe.
I am not sure, but in current Qemu code, I can see the check "pci_is_express" for all virtio-pci devices. If we want to add PM capability for virtio-pci devices, we need to change them to PCIe device I think.

That is one option.
Second option to extend PCI PM cap for non pci device because it is supported.

Quoted 5 lines
Quoted 1 line

--
Best regards,
Jiqian Chen.

#9 lore raw

[virtio-comment] Re: [PATCH v6 1/1] content: Add new feature VIRTIO_F_PRESERVE_RESOURCES

Quoted 26 lines · Parav Pandit
Quoted 26 lines

From: Chen, Jiqian <[email protected]>
Sent: Tuesday, October 24, 2023 5:44 PM

Quoted 20 lines · Parav Pandit
Quoted 20 lines

From: Chen, Jiqian <[email protected]>
Sent: Tuesday, October 24, 2023 4:06 PM

Quoted 10 lines · Parav Pandit
Quoted 9 lines

From: Chen, Jiqian <[email protected]>
Sent: Monday, October 23, 2023 4:09 PM

Quoted 3 lines

I think this can be done without introducing the new register. Can you please check if the PM register itself can serve the purpose instead

of new virtio level register?
Do you mean the system PM register?

No, the device's PM register at transport level.

I tried to find this register(pci level or virtio pci level or virtio driver level), but I didn't find it in Linux kernel or Qemu codes. May I know which register you are referring to specifically? Or which PM state bit you mentioned below?

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

PCI spec's PCI Power Management Capability Structure in section 7.5.2.

Yes, what you point to is PM capability for PCIe device.
But the problem is still that in Qemu code, it will check the condition(pci_bus_is_express or pci_is_express) of all virtio-pci devices in function virtio_pci_realize(), if the virtio devices aren't a PCIe device, it will not add PM capability for them.

PCI PM capability is must for PCIe devices. So may be QEMU code has put it only under is_pcie check.
But it can be done outside of that check as well because this capability exists on PCI too for long time and it is backward compatible.

Do you suggest me to implement PM capability for virtio devices in Qemu firstly, and then to try if the PM capability can work for this scenario?
If so, we will complicate a simple problem. Because there are no other needs to add PM capability for virtio devices for now, if we add it just for preserving resources, it seems unnecessary and unreasonable. And we are not sure if there are other scenarios that are not during the process of PM state changing also need to preserve resources, if have, then the PM register can't cover, but preserve_resources register can. Can I add some notes like "If PM capability is implemented for virtio devices, it may cover this scenario, and if there are no other scenarios that PM can't cover, then we can remove this register " in commit message or spec description and let us continue to add preserve_resources register?

Quoted 105 lines
Quoted 4 lines

And another problem is how about the MMIO transport devices? Since preserve resources is need for all transport type devices.

MMIO lacks such rich PM definitions. If in future MMIO wants to support, it will be extended to match to other transports like PCI.

Quoted 22 lines
Quoted 9 lines
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

I think it is unreasonable to let virtio- device listen the PM state of Guest system.

Guest driver performs any work on the guest systems PM callback events in

the virtio driver.
I didn't find any PM state callback in the virtio driver.

There are virtio_suspend and virtio_resume in case of Linux.

I think what you said virtio_suspend/resume is freeze/restore callback from "struct virtio_driver" or suspend/resume callback from "static const struct dev_pm_ops virtio_pci_pm_ops".
And yes, I agree, if virtio devices have PM capability, maybe we can set PM state in those callback functions.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines

It's more suitable that each device gets notifications from driver, and then do preserving resources operation.

I agree that each device gets the notification from driver. The question is, should it be virtio driver, or existing pci driver which

Quoted 9 lines
Quoted 3 lines
Quoted 3 lines

transitions the state from d0->d3 and d3->d0 is enough.
It seems there isn't existing pci driver to transitions d0 or d3 state. Could you please tell me which one it is specifically? I am very willing to

give a try.

Quoted 2 lines
Quoted 1 line

Virtio-pci modern driver of Linux should be able to.

Yes, I know, it is the VIRTIO_PCI_FLAG_INIT_PM_BIT. But still the two problems I said above.

Both can be resolved without switching to pcie.

Quoted 49 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

Can you please check that?

Quoted 3 lines
Quoted 3 lines

transport-pci.tex \subsubsection{Common configuration

Quoted 3 lines
transport-pci.tex +0 -0
@@ -325,6 +325,7 @@ \subsubsection{Common configuration

structure

Quoted 42 lines
Quoted 42 lines
Quoted 23 lines
Quoted 15 lines
Quoted 7 lines
Quoted 5 lines

layout}\label{sec:Virtio Transport
/* About the administration virtqueue. */
le16 admin_queue_index; /* read-only for driver */
le16 admin_queue_num; /* read-only for driver */
+ le16 preserve_resources; /* read-write */

Preserving these resources in the device implementation takes finite amount

of time.

Quoted 2 lines

Possibly more than 40nsec (time of PCIe write TLP). Hence this register must be a polling register to indicate that

preservation_done.

Quoted 2 lines

This will tell the guest when the preservation is done, and when restoration is

done, so that it can resume upper layers.

Quoted 1 line
Quoted 8 lines
Quoted 2 lines

Please refer to queue_reset definition to learn more about such register

definition.
Thanks, I will refer to "queue_reset". So, I need three values, driver write 1 to let device do preserving resources, driver write 2 to let device do restoring resources, device write 0 to tell driver that preserving or restoring done, am I right?

Quoted 5 lines

Right.

And if the existing pcie pm state bits can do, we can leverage that. If it cannot be used, lets add that reasoning in the commit log to describe this

register.

Quoted 9 lines
Quoted 9 lines
Quoted 4 lines

Lets please make sure that PCIe PM level registers are sufficient/not-sufficient

to decide the addition of this register.
But if the device is not a PCIe device, it doesn't have PM capability, then this will not work. Actually in my local environment, pci_is_express() return false in Qemu, they are not PCIe

device.

Quoted 3 lines

It is reasonable to ask to plug in as PCIe device in 2023 to get new functionality that too you mentioned a gpu device. 😊 Which does not have very long history of any backward compatibility.

Quoted 9 lines
Quoted 4 lines
Quoted 3 lines

Do you suggest me to add PM capability for virtio-gpu or change virtio-gpu to a PCIe device?

PCI Power Management Capability Structure does not seem to be limited to

PCIe.
I am not sure, but in current Qemu code, I can see the check "pci_is_express" for all virtio-pci devices. If we want to add PM capability for virtio-pci devices, we need to change them to PCIe device I think.

That is one option.
Second option to extend PCI PM cap for non pci device because it is supported.

Quoted 5 lines
Quoted 1 line

--
Best regards,
Jiqian Chen.

Signature · 2 lines
Best regards,
Jiqian Chen.
#10 lore raw

[virtio-comment] Re: [PATCH v6 1/1] content: Add new feature VIRTIO_F_PRESERVE_RESOURCES

Quoted 34 lines · Jiqian
Quoted 32 lines · Parav Pandit
Quoted 32 lines

From: Chen, Jiqian <[email protected]>
Sent: Tuesday, October 24, 2023 5:44 PM

Quoted 14 lines · Parav Pandit
Quoted 14 lines

From: Chen, Jiqian <[email protected]>
Sent: Tuesday, October 24, 2023 4:06 PM

Quoted 9 lines · Parav Pandit
Quoted 9 lines

From: Chen, Jiqian <[email protected]>
Sent: Monday, October 23, 2023 4:09 PM

Quoted 3 lines

I think this can be done without introducing the new register. Can you please check if the PM register itself can serve the purpose instead

of new virtio level register?
Do you mean the system PM register?

Quoted 7 lines
Quoted 6 lines
Quoted 1 line

No, the device's PM register at transport level.

I tried to find this register(pci level or virtio pci level or virtio driver level), but I didn't find it in Linux kernel or Qemu codes. May I know which register you are referring to specifically? Or which PM state bit you mentioned below?

PCI spec's PCI Power Management Capability Structure in section 7.5.2.

Yes, what you point to is PM capability for PCIe device.
But the problem is still that in Qemu code, it will check the condition(pci_bus_is_express or pci_is_express) of all virtio-pci devices in function virtio_pci_realize(), if the virtio devices aren't a PCIe device, it will not add PM capability for them.

Quoted 5 lines
Quoted 2 lines

PCI PM capability is must for PCIe devices. So may be QEMU code has put it only under is_pcie check.
But it can be done outside of that check as well because this capability exists on PCI too for long time and it is backward compatible.

Do you suggest me to implement PM capability for virtio devices in Qemu firstly, and then to try if the PM capability can work for this scenario?

virtio devices in qemu already have a PM capability.

Quoted 1 line

If so, we will complicate a simple problem. Because there are no other needs to add PM capability for virtio devices for now, if we add it just for preserving resources, it seems unnecessary and unreasonable. And we are not sure if there are other scenarios that are not during the process of PM state changing also need to preserve resources, if have, then the PM register can't cover, but preserve_resources register can.

One of the selling points of virtio is precisely reusing existing platform capabilities as opposed to coming up with our own. See abstract.tex

Quoted 1 line

Can I add some notes like "If PM capability is implemented for virtio devices, it may cover this scenario, and if there are no other scenarios that PM can't cover, then we can remove this register " in commit message or spec description and let us continue to add preserve_resources register?

We can't remove registers.

Quoted 97 lines
Quoted 97 lines
Quoted 4 lines

And another problem is how about the MMIO transport devices? Since preserve resources is need for all transport type devices.

MMIO lacks such rich PM definitions. If in future MMIO wants to support, it will be extended to match to other transports like PCI.

Quoted 22 lines
Quoted 9 lines
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

I think it is unreasonable to let virtio- device listen the PM state of Guest system.

Guest driver performs any work on the guest systems PM callback events in

the virtio driver.
I didn't find any PM state callback in the virtio driver.

There are virtio_suspend and virtio_resume in case of Linux.

I think what you said virtio_suspend/resume is freeze/restore callback from "struct virtio_driver" or suspend/resume callback from "static const struct dev_pm_ops virtio_pci_pm_ops".
And yes, I agree, if virtio devices have PM capability, maybe we can set PM state in those callback functions.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines

It's more suitable that each device gets notifications from driver, and then do preserving resources operation.

I agree that each device gets the notification from driver. The question is, should it be virtio driver, or existing pci driver which

Quoted 9 lines
Quoted 3 lines
Quoted 3 lines

transitions the state from d0->d3 and d3->d0 is enough.
It seems there isn't existing pci driver to transitions d0 or d3 state. Could you please tell me which one it is specifically? I am very willing to

give a try.

Quoted 2 lines
Quoted 1 line

Virtio-pci modern driver of Linux should be able to.

Yes, I know, it is the VIRTIO_PCI_FLAG_INIT_PM_BIT. But still the two problems I said above.

Both can be resolved without switching to pcie.

Quoted 58 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

Can you please check that?

Quoted 3 lines
Quoted 3 lines

transport-pci.tex \subsubsection{Common configuration

Quoted 3 lines
transport-pci.tex +0 -0
@@ -325,6 +325,7 @@ \subsubsection{Common configuration

structure

Quoted 38 lines
Quoted 38 lines
Quoted 23 lines
Quoted 15 lines
Quoted 7 lines
Quoted 5 lines

layout}\label{sec:Virtio Transport
/* About the administration virtqueue. */
le16 admin_queue_index; /* read-only for driver */
le16 admin_queue_num; /* read-only for driver */
+ le16 preserve_resources; /* read-write */

Preserving these resources in the device implementation takes finite amount

of time.

Quoted 2 lines

Possibly more than 40nsec (time of PCIe write TLP). Hence this register must be a polling register to indicate that

preservation_done.

Quoted 2 lines

This will tell the guest when the preservation is done, and when restoration is

done, so that it can resume upper layers.

Quoted 1 line
Quoted 8 lines
Quoted 2 lines

Please refer to queue_reset definition to learn more about such register

definition.
Thanks, I will refer to "queue_reset". So, I need three values, driver write 1 to let device do preserving resources, driver write 2 to let device do restoring resources, device write 0 to tell driver that preserving or restoring done, am I right?

Quoted 5 lines

Right.

And if the existing pcie pm state bits can do, we can leverage that. If it cannot be used, lets add that reasoning in the commit log to describe this

register.

Quoted 9 lines
Quoted 9 lines
Quoted 4 lines

Lets please make sure that PCIe PM level registers are sufficient/not-sufficient

to decide the addition of this register.
But if the device is not a PCIe device, it doesn't have PM capability, then this will not work. Actually in my local environment, pci_is_express() return false in Qemu, they are not PCIe

Quoted 8 lines
Quoted 7 lines

device.

Quoted 3 lines

It is reasonable to ask to plug in as PCIe device in 2023 to get new functionality that too you mentioned a gpu device. 😊 Which does not have very long history of any backward compatibility.

Do you suggest me to add PM capability for virtio-gpu or change virtio-gpu to a PCIe device?

PCI Power Management Capability Structure does not seem to be limited to

PCIe.
I am not sure, but in current Qemu code, I can see the check "pci_is_express" for all virtio-pci devices. If we want to add PM capability for virtio-pci devices, we need to change them to PCIe device I think.

Quoted 12 lines
Quoted 8 lines

That is one option.
Second option to extend PCI PM cap for non pci device because it is supported.

Quoted 5 lines
Quoted 1 line

--
Best regards,
Jiqian Chen.

Signature · 2 lines
Best regards,
Jiqian Chen.

This publicly archived list offers a means to provide input to the OASIS Virtual I/O Device (VIRTIO) TC.

In order to verify user consent to the Feedback License terms and to minimize spam in the list archive, subscription is required before posting.

Subscribe: [email protected]
Unsubscribe: [email protected]
List help: [email protected]
List archive: https://lists.oasis-open.org/archives/virtio-comment/
Feedback License: https://www.oasis-open.org/who/ipr/feedback_license.pdf
List Guidelines: https://www.oasis-open.org/policies-guidelines/mailing-lists
Committee: https://www.oasis-open.org/committees/virtio/
Join OASIS: https://www.oasis-open.org/join/

#11 lore raw

[virtio-comment] Re: [PATCH v6 1/1] content: Add new feature VIRTIO_F_PRESERVE_RESOURCES

Hi Michael S. Tsirkin and Parav Pandit,
Thank you for your detailed explanation. I will try to use PM cap to fix this issue.

Quoted 165 lines · Michael S. Tsirkin
Quoted 34 lines · Jiqian
Quoted 32 lines · Parav Pandit
Quoted 32 lines

From: Chen, Jiqian <[email protected]>
Sent: Tuesday, October 24, 2023 5:44 PM

Quoted 14 lines · Parav Pandit
Quoted 14 lines

From: Chen, Jiqian <[email protected]>
Sent: Tuesday, October 24, 2023 4:06 PM

Quoted 9 lines · Parav Pandit
Quoted 9 lines

From: Chen, Jiqian <[email protected]>
Sent: Monday, October 23, 2023 4:09 PM

Quoted 3 lines

I think this can be done without introducing the new register. Can you please check if the PM register itself can serve the purpose instead

of new virtio level register?
Do you mean the system PM register?

Quoted 7 lines
Quoted 6 lines
Quoted 1 line

No, the device's PM register at transport level.

I tried to find this register(pci level or virtio pci level or virtio driver level), but I didn't find it in Linux kernel or Qemu codes. May I know which register you are referring to specifically? Or which PM state bit you mentioned below?

PCI spec's PCI Power Management Capability Structure in section 7.5.2.

Yes, what you point to is PM capability for PCIe device.
But the problem is still that in Qemu code, it will check the condition(pci_bus_is_express or pci_is_express) of all virtio-pci devices in function virtio_pci_realize(), if the virtio devices aren't a PCIe device, it will not add PM capability for them.

Quoted 5 lines
Quoted 2 lines

PCI PM capability is must for PCIe devices. So may be QEMU code has put it only under is_pcie check.
But it can be done outside of that check as well because this capability exists on PCI too for long time and it is backward compatible.

Do you suggest me to implement PM capability for virtio devices in Qemu firstly, and then to try if the PM capability can work for this scenario?

virtio devices in qemu already have a PM capability.

Quoted 1 line

If so, we will complicate a simple problem. Because there are no other needs to add PM capability for virtio devices for now, if we add it just for preserving resources, it seems unnecessary and unreasonable. And we are not sure if there are other scenarios that are not during the process of PM state changing also need to preserve resources, if have, then the PM register can't cover, but preserve_resources register can.

One of the selling points of virtio is precisely reusing existing platform capabilities as opposed to coming up with our own. See abstract.tex

Quoted 1 line

Can I add some notes like "If PM capability is implemented for virtio devices, it may cover this scenario, and if there are no other scenarios that PM can't cover, then we can remove this register " in commit message or spec description and let us continue to add preserve_resources register?

We can't remove registers.

Quoted 109 lines
Quoted 105 lines
Quoted 4 lines

And another problem is how about the MMIO transport devices? Since preserve resources is need for all transport type devices.

MMIO lacks such rich PM definitions. If in future MMIO wants to support, it will be extended to match to other transports like PCI.

Quoted 22 lines
Quoted 9 lines
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

I think it is unreasonable to let virtio- device listen the PM state of Guest system.

Guest driver performs any work on the guest systems PM callback events in

the virtio driver.
I didn't find any PM state callback in the virtio driver.

There are virtio_suspend and virtio_resume in case of Linux.

I think what you said virtio_suspend/resume is freeze/restore callback from "struct virtio_driver" or suspend/resume callback from "static const struct dev_pm_ops virtio_pci_pm_ops".
And yes, I agree, if virtio devices have PM capability, maybe we can set PM state in those callback functions.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines

It's more suitable that each device gets notifications from driver, and then do preserving resources operation.

I agree that each device gets the notification from driver. The question is, should it be virtio driver, or existing pci driver which

Quoted 9 lines
Quoted 3 lines
Quoted 3 lines

transitions the state from d0->d3 and d3->d0 is enough.
It seems there isn't existing pci driver to transitions d0 or d3 state. Could you please tell me which one it is specifically? I am very willing to

give a try.

Quoted 2 lines
Quoted 1 line

Virtio-pci modern driver of Linux should be able to.

Yes, I know, it is the VIRTIO_PCI_FLAG_INIT_PM_BIT. But still the two problems I said above.

Both can be resolved without switching to pcie.

Quoted 49 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

Can you please check that?

Quoted 3 lines
Quoted 3 lines

transport-pci.tex \subsubsection{Common configuration

Quoted 3 lines
transport-pci.tex +0 -0
@@ -325,6 +325,7 @@ \subsubsection{Common configuration

structure

Quoted 42 lines
Quoted 42 lines
Quoted 23 lines
Quoted 15 lines
Quoted 7 lines
Quoted 5 lines

layout}\label{sec:Virtio Transport
/* About the administration virtqueue. */
le16 admin_queue_index; /* read-only for driver */
le16 admin_queue_num; /* read-only for driver */
+ le16 preserve_resources; /* read-write */

Preserving these resources in the device implementation takes finite amount

of time.

Quoted 2 lines

Possibly more than 40nsec (time of PCIe write TLP). Hence this register must be a polling register to indicate that

preservation_done.

Quoted 2 lines

This will tell the guest when the preservation is done, and when restoration is

done, so that it can resume upper layers.

Quoted 1 line
Quoted 8 lines
Quoted 2 lines

Please refer to queue_reset definition to learn more about such register

definition.
Thanks, I will refer to "queue_reset". So, I need three values, driver write 1 to let device do preserving resources, driver write 2 to let device do restoring resources, device write 0 to tell driver that preserving or restoring done, am I right?

Quoted 5 lines

Right.

And if the existing pcie pm state bits can do, we can leverage that. If it cannot be used, lets add that reasoning in the commit log to describe this

register.

Quoted 9 lines
Quoted 9 lines
Quoted 4 lines

Lets please make sure that PCIe PM level registers are sufficient/not-sufficient

to decide the addition of this register.
But if the device is not a PCIe device, it doesn't have PM capability, then this will not work. Actually in my local environment, pci_is_express() return false in Qemu, they are not PCIe

device.

Quoted 3 lines

It is reasonable to ask to plug in as PCIe device in 2023 to get new functionality that too you mentioned a gpu device. 😊 Which does not have very long history of any backward compatibility.

Quoted 9 lines
Quoted 4 lines
Quoted 3 lines

Do you suggest me to add PM capability for virtio-gpu or change virtio-gpu to a PCIe device?

PCI Power Management Capability Structure does not seem to be limited to

PCIe.
I am not sure, but in current Qemu code, I can see the check "pci_is_express" for all virtio-pci devices. If we want to add PM capability for virtio-pci devices, we need to change them to PCIe device I think.

That is one option.
Second option to extend PCI PM cap for non pci device because it is supported.

Quoted 5 lines
Quoted 1 line

--
Best regards,
Jiqian Chen.

Signature · 2 lines
Best regards,
Jiqian Chen.
Signature · 2 lines
Best regards,
Jiqian Chen.
#12 lore raw

[virtio-comment] Re: [PATCH v6 1/1] content: Add new feature VIRTIO_F_PRESERVE_RESOURCES

Hi all,
Sorry to reply late.
I don't know if you still remember this problem, let me briefly descript it.
I am working to implement virtgpu S3 function on Xen.
Currently on Xen, if we start a guest through qemu with enabling virtgpu, and then suspend and resume guest. We can find that the guest kernel comes back, but the display doesn't. It just shown a black screen.
That is because during suspending, guest called into qemu and qemu destroyed all display resources and reset renderer. This made the display gone after guest resumed.
So, I add a new command for virtio-gpu that when guest is suspending, it will notify qemu and set parameter(preserver_resource) to 1 and then qemu will preserve resources, and when resuming, guest will notify qemu to set parameter to 0, and then qemu will keep the normal actions. That can help guest's display come back. When I upstream above implementation, Parav and MST suggest me to use the PM capability to fix this problem instead of adding a new command or state bit.
Now, I have tried the PM capability of virtio-gpu, it can't be used to solve this problem.
The reason is:
during guest suspending, it will write D3 state through PM cap, then I can save the resources of virtio-gpu on Qemu side(set preserver_resource to 1),
but during the process of resuming, the state of PM cap will be cleared by qemu resetting(qemu_system_wakeup-> qemu_devices_reset-> virtio_vga_base_reset-> virtio_gpu_gl_reset),
it causes that when guest reads state from PM cap, it will find the virtio-gpu has already been D0 state, so guest will not write D0 through PM cap, so I can't know when to restore the resources(set preserver_resource to 0).
Do you have any other suggestions?
Or can I just fallback to the version that add a new command(VIRTIO_GPU_CMD_PRESERVE_RESOURCE) in virtio-gpu? I think that way is more reasonable and feasible for virtio-gpu to protect display resources during S3. As for other devices, if necessary, they can also refer to the implementation of the virtio-gpu to add new commands to prevent resource loss during S3.

Quoted 170 lines · Jiqian

Hi Michael S. Tsirkin and Parav Pandit,
Thank you for your detailed explanation. I will try to use PM cap to fix this issue.

Quoted 165 lines · Michael S. Tsirkin
Quoted 34 lines · Jiqian
Quoted 32 lines · Parav Pandit
Quoted 32 lines

From: Chen, Jiqian <[email protected]>
Sent: Tuesday, October 24, 2023 5:44 PM

Quoted 14 lines · Parav Pandit
Quoted 14 lines

From: Chen, Jiqian <[email protected]>
Sent: Tuesday, October 24, 2023 4:06 PM

Quoted 9 lines · Parav Pandit
Quoted 9 lines

From: Chen, Jiqian <[email protected]>
Sent: Monday, October 23, 2023 4:09 PM

Quoted 3 lines

I think this can be done without introducing the new register. Can you please check if the PM register itself can serve the purpose instead

of new virtio level register?
Do you mean the system PM register?

Quoted 7 lines
Quoted 6 lines
Quoted 1 line

No, the device's PM register at transport level.

I tried to find this register(pci level or virtio pci level or virtio driver level), but I didn't find it in Linux kernel or Qemu codes. May I know which register you are referring to specifically? Or which PM state bit you mentioned below?

PCI spec's PCI Power Management Capability Structure in section 7.5.2.

Yes, what you point to is PM capability for PCIe device.
But the problem is still that in Qemu code, it will check the condition(pci_bus_is_express or pci_is_express) of all virtio-pci devices in function virtio_pci_realize(), if the virtio devices aren't a PCIe device, it will not add PM capability for them.

Quoted 5 lines
Quoted 2 lines

PCI PM capability is must for PCIe devices. So may be QEMU code has put it only under is_pcie check.
But it can be done outside of that check as well because this capability exists on PCI too for long time and it is backward compatible.

Do you suggest me to implement PM capability for virtio devices in Qemu firstly, and then to try if the PM capability can work for this scenario?

virtio devices in qemu already have a PM capability.

Quoted 1 line

If so, we will complicate a simple problem. Because there are no other needs to add PM capability for virtio devices for now, if we add it just for preserving resources, it seems unnecessary and unreasonable. And we are not sure if there are other scenarios that are not during the process of PM state changing also need to preserve resources, if have, then the PM register can't cover, but preserve_resources register can.

One of the selling points of virtio is precisely reusing existing platform capabilities as opposed to coming up with our own. See abstract.tex

Quoted 1 line

Can I add some notes like "If PM capability is implemented for virtio devices, it may cover this scenario, and if there are no other scenarios that PM can't cover, then we can remove this register " in commit message or spec description and let us continue to add preserve_resources register?

We can't remove registers.

Quoted 109 lines
Quoted 105 lines
Quoted 4 lines

And another problem is how about the MMIO transport devices? Since preserve resources is need for all transport type devices.

MMIO lacks such rich PM definitions. If in future MMIO wants to support, it will be extended to match to other transports like PCI.

Quoted 22 lines
Quoted 9 lines
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

I think it is unreasonable to let virtio- device listen the PM state of Guest system.

Guest driver performs any work on the guest systems PM callback events in

the virtio driver.
I didn't find any PM state callback in the virtio driver.

There are virtio_suspend and virtio_resume in case of Linux.

I think what you said virtio_suspend/resume is freeze/restore callback from "struct virtio_driver" or suspend/resume callback from "static const struct dev_pm_ops virtio_pci_pm_ops".
And yes, I agree, if virtio devices have PM capability, maybe we can set PM state in those callback functions.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines

It's more suitable that each device gets notifications from driver, and then do preserving resources operation.

I agree that each device gets the notification from driver. The question is, should it be virtio driver, or existing pci driver which

Quoted 9 lines
Quoted 3 lines
Quoted 3 lines

transitions the state from d0->d3 and d3->d0 is enough.
It seems there isn't existing pci driver to transitions d0 or d3 state. Could you please tell me which one it is specifically? I am very willing to

give a try.

Quoted 2 lines
Quoted 1 line

Virtio-pci modern driver of Linux should be able to.

Yes, I know, it is the VIRTIO_PCI_FLAG_INIT_PM_BIT. But still the two problems I said above.

Both can be resolved without switching to pcie.

Quoted 49 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

Can you please check that?

Quoted 3 lines
Quoted 3 lines

transport-pci.tex \subsubsection{Common configuration

Quoted 3 lines
transport-pci.tex +0 -0
@@ -325,6 +325,7 @@ \subsubsection{Common configuration

structure

Quoted 42 lines
Quoted 42 lines
Quoted 23 lines
Quoted 15 lines
Quoted 7 lines
Quoted 5 lines

layout}\label{sec:Virtio Transport
/* About the administration virtqueue. */
le16 admin_queue_index; /* read-only for driver */
le16 admin_queue_num; /* read-only for driver */
+ le16 preserve_resources; /* read-write */

Preserving these resources in the device implementation takes finite amount

of time.

Quoted 2 lines

Possibly more than 40nsec (time of PCIe write TLP). Hence this register must be a polling register to indicate that

preservation_done.

Quoted 2 lines

This will tell the guest when the preservation is done, and when restoration is

done, so that it can resume upper layers.

Quoted 1 line
Quoted 8 lines
Quoted 2 lines

Please refer to queue_reset definition to learn more about such register

definition.
Thanks, I will refer to "queue_reset". So, I need three values, driver write 1 to let device do preserving resources, driver write 2 to let device do restoring resources, device write 0 to tell driver that preserving or restoring done, am I right?

Quoted 5 lines

Right.

And if the existing pcie pm state bits can do, we can leverage that. If it cannot be used, lets add that reasoning in the commit log to describe this

register.

Quoted 9 lines
Quoted 9 lines
Quoted 4 lines

Lets please make sure that PCIe PM level registers are sufficient/not-sufficient

to decide the addition of this register.
But if the device is not a PCIe device, it doesn't have PM capability, then this will not work. Actually in my local environment, pci_is_express() return false in Qemu, they are not PCIe

device.

Quoted 3 lines

It is reasonable to ask to plug in as PCIe device in 2023 to get new functionality that too you mentioned a gpu device. 😊 Which does not have very long history of any backward compatibility.

Quoted 9 lines
Quoted 4 lines
Quoted 3 lines

Do you suggest me to add PM capability for virtio-gpu or change virtio-gpu to a PCIe device?

PCI Power Management Capability Structure does not seem to be limited to

PCIe.
I am not sure, but in current Qemu code, I can see the check "pci_is_express" for all virtio-pci devices. If we want to add PM capability for virtio-pci devices, we need to change them to PCIe device I think.

That is one option.
Second option to extend PCI PM cap for non pci device because it is supported.

Quoted 5 lines
Quoted 1 line

--
Best regards,
Jiqian Chen.

Signature · 2 lines
Best regards,
Jiqian Chen.
Signature · 2 lines
Best regards,
Jiqian Chen.
#13 lore raw

[virtio-comment] RE: [PATCH v6 1/1] content: Add new feature VIRTIO_F_PRESERVE_RESOURCES

Hi Jiqian,

Quoted 23 lines

From: Chen, Jiqian <[email protected]>
Sent: Friday, January 12, 2024 1:11 PM

Hi all,
Sorry to reply late.
I don't know if you still remember this problem, let me briefly descript it. I am working to implement virtgpu S3 function on Xen.
Currently on Xen, if we start a guest through qemu with enabling virtgpu, and then suspend and resume guest. We can find that the guest kernel comes back, but the display doesn't. It just shown a black screen.
That is because during suspending, guest called into qemu and qemu destroyed all display resources and reset renderer. This made the display gone after guest resumed.
So, I add a new command for virtio-gpu that when guest is suspending, it will notify qemu and set parameter(preserver_resource) to 1 and then qemu will preserve resources, and when resuming, guest will notify qemu to set parameter to 0, and then qemu will keep the normal actions. That can help guest's display come back.
When I upstream above implementation, Parav and MST suggest me to use the PM capability to fix this problem instead of adding a new command or state bit.
Now, I have tried the PM capability of virtio-gpu, it can't be used to solve this

Quoted 8 lines

problem.
The reason is:
during guest suspending, it will write D3 state through PM cap, then I can save the resources of virtio-gpu on Qemu side(set preserver_resource to 1), but during the process of resuming, the state of PM cap will be cleared by qemu resetting(qemu_system_wakeup-> qemu_devices_reset-> virtio_vga_base_reset-> virtio_gpu_gl_reset), it causes that when guest reads state from PM cap, it will find the virtio-gpu has already been D0 state,

This behavior needs to be fixed. As the spec listed out, " This 2-bit field is used both to determine the current power state of a Function"

So device needs to return D3 in the PowerState field. This is must.

In addition to it, an additional busy_poll register is helpful that indicates the device is ready to use.
This is because 10msec is the timeout set by the PCI spec.
This can be hard for the devices to implement if the large GPU state is being read from files or slow media or for other hw devices in large quantities.

This limit comes from the PCI spec normative of below.

After transitioning a VF from D3Hot to D0, at least one of the following is true:
◦ At least 10 ms has passed since the request to enter D0 was issued.

So Readiness Time Reporting capability is not so useful.

Hence, after PM state to D3->D0 transition is successful, virtio level PCI register is useful to ensure that device is resumed to drive rest of the registers.

Quoted 205 lines

so
guest will not write D0 through PM cap, so I can't know when to restore the resources(set preserver_resource to 0).
Do you have any other suggestions?
Or can I just fallback to the version that add a new command(VIRTIO_GPU_CMD_PRESERVE_RESOURCE) in virtio-gpu? I think that way is more reasonable and feasible for virtio-gpu to protect display resources during S3. As for other devices, if necessary, they can also refer to the implementation of the virtio-gpu to add new commands to prevent resource loss during S3.

Quoted 34 lines · Jiqian

Hi Michael S. Tsirkin and Parav Pandit, Thank you for your detailed explanation. I will try to use PM cap to fix this issue.

Quoted 30 lines · Michael S. Tsirkin
Quoted 29 lines · Jiqian
Quoted 27 lines · Parav Pandit
Quoted 27 lines

From: Chen, Jiqian <[email protected]>
Sent: Tuesday, October 24, 2023 5:44 PM

Quoted 21 lines · Parav Pandit
Quoted 12 lines

From: Chen, Jiqian <[email protected]>
Sent: Tuesday, October 24, 2023 4:06 PM

Quoted 7 lines · Parav Pandit
Quoted 7 lines

From: Chen, Jiqian <[email protected]>
Sent: Monday, October 23, 2023 4:09 PM

Quoted 3 lines

I think this can be done without introducing the new register. Can you please check if the PM register itself can serve the purpose instead

Quoted 8 lines
Quoted 3 lines
Quoted 2 lines

of new virtio level register?
Do you mean the system PM register?

No, the device's PM register at transport level.

I tried to find this register(pci level or virtio pci level or virtio driver level), but I didn't find it in Linux kernel or Qemu codes. May I know which register you are referring to specifically? Or which PM state bit you mentioned below?

PCI spec's PCI Power Management Capability Structure in section

7.5.2.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

Yes, what you point to is PM capability for PCIe device. But the problem is still that in Qemu code, it will check the condition(pci_bus_is_express or pci_is_express) of all virtio-pci devices in function virtio_pci_realize(), if the virtio devices aren't a PCIe device, it will not add PM capability for them.

PCI PM capability is must for PCIe devices. So may be QEMU code has put

it only under is_pcie check.

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

But it can be done outside of that check as well because this capability

exists on PCI too for long time and it is backward compatible.

Quoted 8 lines
Quoted 8 lines
Quoted 3 lines

Do you suggest me to implement PM capability for virtio devices in Qemu firstly, and then to try if the PM capability can work for this scenario?

virtio devices in qemu already have a PM capability.

Quoted 1 line

If so, we will complicate a simple problem. Because there are no other

needs to add PM capability for virtio devices for now, if we add it just for preserving resources, it seems unnecessary and unreasonable. And we are not sure if there are other scenarios that are not during the process of PM state changing also need to preserve resources, if have, then the PM register can't cover, but preserve_resources register can.

Quoted 7 lines
Quoted 7 lines

One of the selling points of virtio is precisely reusing existing platform capabilities as opposed to coming up with our own. See abstract.tex

Quoted 1 line

Can I add some notes like "If PM capability is implemented for virtio

devices, it may cover this scenario, and if there are no other scenarios that PM can't cover, then we can remove this register " in commit message or spec description and let us continue to add preserve_resources register?

Quoted 8 lines
Quoted 8 lines

We can't remove registers.

Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

And another problem is how about the MMIO transport devices? Since preserve resources is need for all transport type devices.

MMIO lacks such rich PM definitions. If in future MMIO wants to

support, it will be extended to match to other transports like PCI.

Quoted 82 lines
Quoted 82 lines
Quoted 82 lines
Quoted 82 lines
Quoted 27 lines
Quoted 10 lines
Quoted 9 lines
Quoted 6 lines
Quoted 4 lines

I think it is unreasonable to let virtio- device listen the PM state of Guest system.

Guest driver performs any work on the guest systems PM callback events in

the virtio driver.
I didn't find any PM state callback in the virtio driver.

There are virtio_suspend and virtio_resume in case of Linux.

I think what you said virtio_suspend/resume is freeze/restore callback from "struct virtio_driver" or suspend/resume callback from "static const struct dev_pm_ops virtio_pci_pm_ops". And yes, I agree, if virtio devices have PM capability, maybe we can set PM state in those callback functions.

Quoted 11 lines
Quoted 11 lines
Quoted 7 lines
Quoted 4 lines

It's more suitable that each device gets notifications from driver, and then do preserving resources operation.

I agree that each device gets the notification from driver. The question is, should it be virtio driver, or existing pci driver which

transitions the state from d0->d3 and d3->d0 is enough. It seems there isn't existing pci driver to transitions d0 or d3 state. Could you please tell me which one it is specifically? I am very willing to

Quoted 6 lines

give a try.

Quoted 2 lines
Quoted 1 line

Virtio-pci modern driver of Linux should be able to.

Yes, I know, it is the VIRTIO_PCI_FLAG_INIT_PM_BIT. But still the two problems I said above.

Both can be resolved without switching to pcie.

Quoted 47 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

Can you please check that?

Quoted 3 lines
Quoted 3 lines

transport-pci.tex \subsubsection{Common configuration

Quoted 3 lines
transport-pci.tex +0 -0
@@ -325,6 +325,7 @@ \subsubsection{Common configuration

structure

Quoted 40 lines
Quoted 40 lines
Quoted 25 lines
Quoted 16 lines
Quoted 7 lines
Quoted 5 lines

layout}\label{sec:Virtio Transport
/* About the administration virtqueue. */
le16 admin_queue_index; /* read-only for driver */
le16 admin_queue_num; /* read-only for driver */
+ le16 preserve_resources; /* read-write */

Preserving these resources in the device implementation takes finite amount

of time.

Quoted 3 lines

Possibly more than 40nsec (time of PCIe write TLP). Hence this register must be a polling register to indicate that

preservation_done.

Quoted 2 lines

This will tell the guest when the preservation is done, and when restoration is

done, so that it can resume upper layers.

Quoted 1 line
Quoted 9 lines
Quoted 2 lines

Please refer to queue_reset definition to learn more about such register

definition.
Thanks, I will refer to "queue_reset". So, I need three values, driver write 1 to let device do preserving resources, driver write
2 to let device do restoring resources, device write 0 to tell driver that preserving or restoring done, am I right?

Quoted 5 lines

Right.

And if the existing pcie pm state bits can do, we can leverage that. If it cannot be used, lets add that reasoning in the commit log to describe this

register.

Quoted 9 lines
Quoted 9 lines
Quoted 4 lines

Lets please make sure that PCIe PM level registers are sufficient/not-sufficient

to decide the addition of this register.
But if the device is not a PCIe device, it doesn't have PM capability, then this will not work. Actually in my local environment, pci_is_express() return false in Qemu, they are not PCIe

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

device.

Quoted 3 lines

It is reasonable to ask to plug in as PCIe device in 2023 to get new functionality that too you mentioned a gpu device. 😊 Which does not have very long history of any backward

compatibility.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

Do you suggest me to add PM capability for virtio-gpu or change virtio-gpu to a PCIe device?

PCI Power Management Capability Structure does not seem to be limited to

PCIe.
I am not sure, but in current Qemu code, I can see the check

"pci_is_express"

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines

for all virtio-pci devices. If we want to add PM capability for virtio-pci devices, we need to change them to PCIe device I think.

That is one option.
Second option to extend PCI PM cap for non pci device because it is

supported.

Quoted 12 lines
Quoted 11 lines
Quoted 10 lines
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

--
Best regards,
Jiqian Chen.

--
Best regards,
Jiqian Chen.

--
Best regards,
Jiqian Chen.

#14 lore raw

[virtio-comment] Re: [PATCH v6 1/1] content: Add new feature VIRTIO_F_PRESERVE_RESOURCES

Quoted 33 lines · Parav Pandit

Hi Jiqian,

Quoted 23 lines

From: Chen, Jiqian <[email protected]>
Sent: Friday, January 12, 2024 1:11 PM

Hi all,
Sorry to reply late.
I don't know if you still remember this problem, let me briefly descript it. I am working to implement virtgpu S3 function on Xen.
Currently on Xen, if we start a guest through qemu with enabling virtgpu, and then suspend and resume guest. We can find that the guest kernel comes back, but the display doesn't. It just shown a black screen.
That is because during suspending, guest called into qemu and qemu destroyed all display resources and reset renderer. This made the display gone after guest resumed.
So, I add a new command for virtio-gpu that when guest is suspending, it will notify qemu and set parameter(preserver_resource) to 1 and then qemu will preserve resources, and when resuming, guest will notify qemu to set parameter to 0, and then qemu will keep the normal actions. That can help guest's display come back.
When I upstream above implementation, Parav and MST suggest me to use the PM capability to fix this problem instead of adding a new command or state bit.
Now, I have tried the PM capability of virtio-gpu, it can't be used to solve this

Quoted 8 lines

problem.
The reason is:
during guest suspending, it will write D3 state through PM cap, then I can save the resources of virtio-gpu on Qemu side(set preserver_resource to 1), but during the process of resuming, the state of PM cap will be cleared by qemu resetting(qemu_system_wakeup-> qemu_devices_reset-> virtio_vga_base_reset-> virtio_gpu_gl_reset), it causes that when guest reads state from PM cap, it will find the virtio-gpu has already been D0 state,

Quoted 1 line

This behavior needs to be fixed. As the spec listed out, " This 2-bit field is used both to determine the current power state of a Function"

Do you mean it is wrong to reset PM cap when vritio_gpu reset in current qemu code? Why? Shouldn't all device states, including PM registers, be reset during the process of virtio-gpu reset?

Quoted 2 lines

So device needs to return D3 in the PowerState field. This is must.

But current behavior is a kind of soft reset, I think(!PCI_PM_CTRL_NO_SOFT_RESET). The pm cap is reset by qemu is reasonable.

Quoted 219 lines

In addition to it, an additional busy_poll register is helpful that indicates the device is ready to use.
This is because 10msec is the timeout set by the PCI spec.
This can be hard for the devices to implement if the large GPU state is being read from files or slow media or for other hw devices in large quantities.

This limit comes from the PCI spec normative of below.

After transitioning a VF from D3Hot to D0, at least one of the following is true:
◦ At least 10 ms has passed since the request to enter D0 was issued.

So Readiness Time Reporting capability is not so useful.

Hence, after PM state to D3->D0 transition is successful, virtio level PCI register is useful to ensure that device is resumed to drive rest of the registers.

Quoted 205 lines

so
guest will not write D0 through PM cap, so I can't know when to restore the resources(set preserver_resource to 0).
Do you have any other suggestions?
Or can I just fallback to the version that add a new command(VIRTIO_GPU_CMD_PRESERVE_RESOURCE) in virtio-gpu? I think that way is more reasonable and feasible for virtio-gpu to protect display resources during S3. As for other devices, if necessary, they can also refer to the implementation of the virtio-gpu to add new commands to prevent resource loss during S3.

Quoted 34 lines · Jiqian

Hi Michael S. Tsirkin and Parav Pandit, Thank you for your detailed explanation. I will try to use PM cap to fix this issue.

Quoted 30 lines · Michael S. Tsirkin
Quoted 29 lines · Jiqian
Quoted 27 lines · Parav Pandit
Quoted 27 lines

From: Chen, Jiqian <[email protected]>
Sent: Tuesday, October 24, 2023 5:44 PM

Quoted 21 lines · Parav Pandit
Quoted 12 lines

From: Chen, Jiqian <[email protected]>
Sent: Tuesday, October 24, 2023 4:06 PM

Quoted 7 lines · Parav Pandit
Quoted 7 lines

From: Chen, Jiqian <[email protected]>
Sent: Monday, October 23, 2023 4:09 PM

Quoted 3 lines

I think this can be done without introducing the new register. Can you please check if the PM register itself can serve the purpose instead

Quoted 8 lines
Quoted 3 lines
Quoted 2 lines

of new virtio level register?
Do you mean the system PM register?

No, the device's PM register at transport level.

I tried to find this register(pci level or virtio pci level or virtio driver level), but I didn't find it in Linux kernel or Qemu codes. May I know which register you are referring to specifically? Or which PM state bit you mentioned below?

PCI spec's PCI Power Management Capability Structure in section

7.5.2.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

Yes, what you point to is PM capability for PCIe device. But the problem is still that in Qemu code, it will check the condition(pci_bus_is_express or pci_is_express) of all virtio-pci devices in function virtio_pci_realize(), if the virtio devices aren't a PCIe device, it will not add PM capability for them.

PCI PM capability is must for PCIe devices. So may be QEMU code has put

it only under is_pcie check.

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

But it can be done outside of that check as well because this capability

exists on PCI too for long time and it is backward compatible.

Quoted 8 lines
Quoted 8 lines
Quoted 3 lines

Do you suggest me to implement PM capability for virtio devices in Qemu firstly, and then to try if the PM capability can work for this scenario?

virtio devices in qemu already have a PM capability.

Quoted 1 line

If so, we will complicate a simple problem. Because there are no other

needs to add PM capability for virtio devices for now, if we add it just for preserving resources, it seems unnecessary and unreasonable. And we are not sure if there are other scenarios that are not during the process of PM state changing also need to preserve resources, if have, then the PM register can't cover, but preserve_resources register can.

Quoted 7 lines
Quoted 7 lines

One of the selling points of virtio is precisely reusing existing platform capabilities as opposed to coming up with our own. See abstract.tex

Quoted 1 line

Can I add some notes like "If PM capability is implemented for virtio

devices, it may cover this scenario, and if there are no other scenarios that PM can't cover, then we can remove this register " in commit message or spec description and let us continue to add preserve_resources register?

Quoted 8 lines
Quoted 8 lines

We can't remove registers.

Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

And another problem is how about the MMIO transport devices? Since preserve resources is need for all transport type devices.

MMIO lacks such rich PM definitions. If in future MMIO wants to

support, it will be extended to match to other transports like PCI.

Quoted 82 lines
Quoted 82 lines
Quoted 82 lines
Quoted 82 lines
Quoted 27 lines
Quoted 10 lines
Quoted 9 lines
Quoted 6 lines
Quoted 4 lines

I think it is unreasonable to let virtio- device listen the PM state of Guest system.

Guest driver performs any work on the guest systems PM callback events in

the virtio driver.
I didn't find any PM state callback in the virtio driver.

There are virtio_suspend and virtio_resume in case of Linux.

I think what you said virtio_suspend/resume is freeze/restore callback from "struct virtio_driver" or suspend/resume callback from "static const struct dev_pm_ops virtio_pci_pm_ops". And yes, I agree, if virtio devices have PM capability, maybe we can set PM state in those callback functions.

Quoted 11 lines
Quoted 11 lines
Quoted 7 lines
Quoted 4 lines

It's more suitable that each device gets notifications from driver, and then do preserving resources operation.

I agree that each device gets the notification from driver. The question is, should it be virtio driver, or existing pci driver which

transitions the state from d0->d3 and d3->d0 is enough. It seems there isn't existing pci driver to transitions d0 or d3 state. Could you please tell me which one it is specifically? I am very willing to

Quoted 6 lines

give a try.

Quoted 2 lines
Quoted 1 line

Virtio-pci modern driver of Linux should be able to.

Yes, I know, it is the VIRTIO_PCI_FLAG_INIT_PM_BIT. But still the two problems I said above.

Both can be resolved without switching to pcie.

Quoted 47 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

Can you please check that?

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

--- a/transport-pci.tex
+++ b/transport-pci.tex
@@ -325,6 +325,7 @@ \subsubsection{Common configuration

structure

Quoted 40 lines
Quoted 40 lines
Quoted 25 lines
Quoted 16 lines
Quoted 7 lines
Quoted 5 lines

layout}\label{sec:Virtio Transport
/* About the administration virtqueue. */
le16 admin_queue_index; /* read-only for driver */
le16 admin_queue_num; /* read-only for driver */
+ le16 preserve_resources; /* read-write */

Preserving these resources in the device implementation takes finite amount

of time.

Quoted 3 lines

Possibly more than 40nsec (time of PCIe write TLP). Hence this register must be a polling register to indicate that

preservation_done.

Quoted 2 lines

This will tell the guest when the preservation is done, and when restoration is

done, so that it can resume upper layers.

Quoted 1 line
Quoted 9 lines
Quoted 2 lines

Please refer to queue_reset definition to learn more about such register

definition.
Thanks, I will refer to "queue_reset". So, I need three values, driver write 1 to let device do preserving resources, driver write
2 to let device do restoring resources, device write 0 to tell driver that preserving or restoring done, am I right?

Quoted 5 lines

Right.

And if the existing pcie pm state bits can do, we can leverage that. If it cannot be used, lets add that reasoning in the commit log to describe this

register.

Quoted 9 lines
Quoted 9 lines
Quoted 4 lines

Lets please make sure that PCIe PM level registers are sufficient/not-sufficient

to decide the addition of this register.
But if the device is not a PCIe device, it doesn't have PM capability, then this will not work. Actually in my local environment, pci_is_express() return false in Qemu, they are not PCIe

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

device.

Quoted 3 lines

It is reasonable to ask to plug in as PCIe device in 2023 to get new functionality that too you mentioned a gpu device. 😊 Which does not have very long history of any backward

compatibility.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

Do you suggest me to add PM capability for virtio-gpu or change virtio-gpu to a PCIe device?

PCI Power Management Capability Structure does not seem to be limited to

PCIe.
I am not sure, but in current Qemu code, I can see the check

"pci_is_express"

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines

for all virtio-pci devices. If we want to add PM capability for virtio-pci devices, we need to change them to PCIe device I think.

That is one option.
Second option to extend PCI PM cap for non pci device because it is

supported.

Quoted 12 lines
Quoted 11 lines
Quoted 10 lines
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

--
Best regards,
Jiqian Chen.

--
Best regards,
Jiqian Chen.

--
Best regards,
Jiqian Chen.

Signature · 2 lines
Best regards,
Jiqian Chen.
#15 lore raw

[virtio-comment] RE: [PATCH v6 1/1] content: Add new feature VIRTIO_F_PRESERVE_RESOURCES

Quoted 44 lines

From: Chen, Jiqian <[email protected]>
Sent: Friday, January 12, 2024 1:55 PM

Quoted 13 lines · Parav Pandit

Hi Jiqian,

Quoted 11 lines

From: Chen, Jiqian <[email protected]>
Sent: Friday, January 12, 2024 1:11 PM

Hi all,
Sorry to reply late.
I don't know if you still remember this problem, let me briefly descript it. I am working to implement virtgpu S3 function on Xen.
Currently on Xen, if we start a guest through qemu with enabling virtgpu, and then suspend and resume guest. We can find that the guest kernel comes back, but the display doesn't. It just shown a black

screen.

Quoted 9 lines
Quoted 9 lines

That is because during suspending, guest called into qemu and qemu destroyed all display resources and reset renderer. This made the display gone after guest resumed.
So, I add a new command for virtio-gpu that when guest is suspending, it will notify qemu and set parameter(preserver_resource) to 1 and then qemu will preserve resources, and when resuming, guest will notify qemu to set parameter to 0, and then qemu will keep the normal actions. That can help guest's display come back.
When I upstream above implementation, Parav and MST suggest me to

use

Quoted 13 lines
Quoted 13 lines

the PM capability to fix this problem instead of adding a new command or state bit.
Now, I have tried the PM capability of virtio-gpu, it can't be used to solve this problem.
The reason is:
during guest suspending, it will write D3 state through PM cap, then I can save the resources of virtio-gpu on Qemu side(set preserver_resource to 1), but during the process of resuming, the state of PM cap will be cleared by qemu resetting(qemu_system_wakeup-> qemu_devices_reset-> virtio_vga_base_reset-> virtio_gpu_gl_reset), it causes that when guest reads state from PM cap, it will find the virtio-gpu has already been D0 state,

Quoted 4 lines
Quoted 1 line

This behavior needs to be fixed. As the spec listed out, " This 2-bit field is

used both to determine the current power state of a Function" Do you mean it is wrong to reset PM cap when vritio_gpu reset in current qemu code? Why?

Because PM is implementing the support from D3->d0 transition and if it device in D3, the device needs to respond that it is in D3 to match the PCI spec.

Quoted 2 lines

Shouldn't all device states, including PM registers, be reset during the process of virtio-gpu reset?

If No_Soft_Reset== 0, no device context to be preserved.
If No_Soft_Reset == 1, device to preserve minimal registers and other things listed in pci spec.

Quoted 6 lines
Quoted 3 lines

So device needs to return D3 in the PowerState field. This is must.

But current behavior is a kind of soft reset, I think(!PCI_PM_CTRL_NO_SOFT_RESET). The pm cap is reset by qemu is reasonable.

What you described is, you need to do No_Soft_Reset=1, so please set the cap accordingly to achieve the restore.

Also in your case the if the QEMU knows that it will have to resume the device soon. Hence, it can well prepare the gpu context before resuming the vcpus. In such case, the extra register wouldn’t be necessary.
Having PM control register is anyway needed to drive the device properly.

Having the extra busy_poll register is flexible. So please evaluate if you need it or not.

Quoted 242 lines
Quoted 3 lines

In addition to it, an additional busy_poll register is helpful that indicates the

device is ready to use.

Quoted 2 lines

This is because 10msec is the timeout set by the PCI spec.
This can be hard for the devices to implement if the large GPU state is being

read from files or slow media or for other hw devices in large quantities.

Quoted 4 lines

This limit comes from the PCI spec normative of below.

After transitioning a VF from D3Hot to D0, at least one of the following is

true:

Quoted 5 lines

◦ At least 10 ms has passed since the request to enter D0 was issued.

So Readiness Time Reporting capability is not so useful.

Hence, after PM state to D3->D0 transition is successful, virtio level PCI

register is useful to ensure that device is resumed to drive rest of the registers.

Quoted 7 lines
Quoted 7 lines

so
guest will not write D0 through PM cap, so I can't know when to restore the resources(set preserver_resource to 0).
Do you have any other suggestions?
Or can I just fallback to the version that add a new command(VIRTIO_GPU_CMD_PRESERVE_RESOURCE) in virtio-gpu? I think

that

Quoted 28 lines
Quoted 28 lines

way is more reasonable and feasible for virtio-gpu to protect display resources during S3. As for other devices, if necessary, they can also refer to the implementation of the virtio-gpu to add new commands to prevent resource loss during S3.

Quoted 22 lines · Jiqian

Hi Michael S. Tsirkin and Parav Pandit, Thank you for your detailed explanation. I will try to use PM cap to fix this issue.

Quoted 18 lines · Michael S. Tsirkin
Quoted 17 lines · Jiqian
Quoted 15 lines · Parav Pandit
Quoted 15 lines

From: Chen, Jiqian <[email protected]>
Sent: Tuesday, October 24, 2023 5:44 PM

Quoted 9 lines · Parav Pandit
Quoted 9 lines

From: Chen, Jiqian <[email protected]>
Sent: Tuesday, October 24, 2023 4:06 PM

Quoted 4 lines · Parav Pandit
Quoted 3 lines

From: Chen, Jiqian <[email protected]>
Sent: Monday, October 23, 2023 4:09 PM

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
Quoted 5 lines
Quoted 3 lines

I think this can be done without introducing the new register.
Can you please check if the PM register itself can serve
the purpose instead

of new virtio level register?
Do you mean the system PM register?

No, the device's PM register at transport level.

I tried to find this register(pci level or virtio pci level or virtio driver level), but I didn't find it in Linux kernel or Qemu

codes.

Quoted 10 lines
Quoted 10 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines

May I know which register you are referring to specifically? Or which PM state bit you mentioned below?

PCI spec's PCI Power Management Capability Structure in section

7.5.2.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Yes, what you point to is PM capability for PCIe device. But the problem is still that in Qemu code, it will check the condition(pci_bus_is_express or pci_is_express) of all virtio-pci devices in function virtio_pci_realize(), if the virtio devices aren't a PCIe device, it will not add PM capability for

them.

Quoted 13 lines
Quoted 13 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

PCI PM capability is must for PCIe devices. So may be QEMU code has put

it only under is_pcie check.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

But it can be done outside of that check as well because this capability

exists on PCI too for long time and it is backward compatible.

Quoted 7 lines
Quoted 7 lines
Quoted 3 lines

Do you suggest me to implement PM capability for virtio devices in Qemu firstly, and then to try if the PM capability can work for this scenario?

virtio devices in qemu already have a PM capability.

Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

If so, we will complicate a simple problem. Because there are no other

needs to add PM capability for virtio devices for now, if we add it just for preserving resources, it seems unnecessary and unreasonable. And we are not sure if there are other scenarios that are not during the process of PM state changing also need to preserve resources, if have, then the PM register can't cover, but preserve_resources register

can.

Quoted 11 lines
Quoted 11 lines
Quoted 8 lines
Quoted 8 lines

One of the selling points of virtio is precisely reusing existing platform capabilities as opposed to coming up with our own. See abstract.tex

Quoted 2 lines

Can I add some notes like "If PM capability is implemented for virtio

devices, it may cover this scenario, and if there are no other scenarios that PM can't cover, then we can remove this register " in commit message or spec description and let us continue to add

preserve_resources register?

Quoted 42 lines
Quoted 42 lines
Quoted 8 lines
Quoted 8 lines

We can't remove registers.

Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

And another problem is how about the MMIO transport devices? Since preserve resources is need for all transport type devices.

MMIO lacks such rich PM definitions. If in future MMIO wants to

support, it will be extended to match to other transports like PCI.

Quoted 33 lines
Quoted 33 lines
Quoted 33 lines
Quoted 33 lines
Quoted 33 lines
Quoted 10 lines
Quoted 9 lines
Quoted 6 lines
Quoted 4 lines

I think it is unreasonable to let virtio- device listen the PM state of Guest system.

Guest driver performs any work on the guest systems PM callback events in

the virtio driver.
I didn't find any PM state callback in the virtio driver.

There are virtio_suspend and virtio_resume in case of Linux.

I think what you said virtio_suspend/resume is freeze/restore callback from "struct virtio_driver" or suspend/resume callback from "static const struct dev_pm_ops virtio_pci_pm_ops". And yes, I agree, if virtio devices have PM capability, maybe we can set PM state in those callback functions.

Quoted 11 lines
Quoted 11 lines
Quoted 7 lines
Quoted 4 lines

It's more suitable that each device gets notifications from driver, and then do preserving resources operation.

I agree that each device gets the notification from driver. The question is, should it be virtio driver, or existing pci driver which

transitions the state from d0->d3 and d3->d0 is enough. It seems there isn't existing pci driver to transitions d0 or d3 state. Could you please tell me which one it is specifically? I am very willing to

give a try.

Quoted 2 lines
Quoted 1 line

Virtio-pci modern driver of Linux should be able to.

Yes, I know, it is the VIRTIO_PCI_FLAG_INIT_PM_BIT. But still the two problems I said above.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

Both can be resolved without switching to pcie.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

Can you please check that?

Quoted 3 lines
Quoted 3 lines

--- a/transport-pci.tex
+++ b/transport-pci.tex
@@ -325,6 +325,7 @@ \subsubsection{Common

configuration

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

structure

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

layout}\label{sec:Virtio Transport
/* About the administration virtqueue. */
le16 admin_queue_index; /* read-only for driver

*/

Quoted 22 lines
Quoted 22 lines
Quoted 22 lines
Quoted 22 lines
Quoted 22 lines
Quoted 22 lines
Quoted 22 lines
Quoted 22 lines
Quoted 22 lines
Quoted 22 lines
Quoted 22 lines
Quoted 4 lines

le16 admin_queue_num; /* read-only for driver */
+ le16 preserve_resources; /* read-write */
Preserving these resources in the device implementation
takes finite amount

of time.

Quoted 3 lines

Possibly more than 40nsec (time of PCIe write TLP).
Hence this register must be a polling register to indicate
that

preservation_done.

Quoted 2 lines

This will tell the guest when the preservation is done, and
when restoration is

done, so that it can resume upper layers.

Quoted 3 lines

Please refer to queue_reset definition to learn more about
such register

definition.
Thanks, I will refer to "queue_reset". So, I need three values, driver write 1 to let device do preserving resources, driver write
2 to let device do restoring resources, device write 0 to tell driver that preserving or restoring done, am I right?

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Right.

And if the existing pcie pm state bits can do, we can leverage

that.

Quoted 45 lines
Quoted 45 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 2 lines

If it cannot be used, lets add that reasoning in the commit log to describe this

register.

Quoted 9 lines
Quoted 9 lines
Quoted 4 lines

Lets please make sure that PCIe PM level registers are
sufficient/not-sufficient

to decide the addition of this register.
But if the device is not a PCIe device, it doesn't have PM capability, then this will not work. Actually in my local environment, pci_is_express() return false in Qemu, they are not PCIe

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

device.

Quoted 3 lines

It is reasonable to ask to plug in as PCIe device in 2023 to get new functionality that too you mentioned a gpu device. 😊 Which does not have very long history of any backward

compatibility.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

Do you suggest me to add PM capability for virtio-gpu or change virtio-gpu to a PCIe device?

PCI Power Management Capability Structure does not seem to be limited to

PCIe.
I am not sure, but in current Qemu code, I can see the check

"pci_is_express"

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

for all virtio-pci devices. If we want to add PM capability for virtio-pci devices, we need to change them to PCIe device I think.

That is one option.
Second option to extend PCI PM cap for non pci device because it is

supported.

Quoted 12 lines
Quoted 11 lines
Quoted 10 lines
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

--
Best regards,
Jiqian Chen.

--
Best regards,
Jiqian Chen.

Quoted 3 lines
Quoted 3 lines

--
Best regards,
Jiqian Chen.

--
Best regards,
Jiqian Chen.

#16 lore raw

[virtio-comment] Re: [PATCH v6 1/1] content: Add new feature VIRTIO_F_PRESERVE_RESOURCES

Quoted 61 lines · Parav Pandit
Quoted 44 lines

From: Chen, Jiqian <[email protected]>
Sent: Friday, January 12, 2024 1:55 PM

Quoted 13 lines · Parav Pandit

Hi Jiqian,

Quoted 11 lines

From: Chen, Jiqian <[email protected]>
Sent: Friday, January 12, 2024 1:11 PM

Hi all,
Sorry to reply late.
I don't know if you still remember this problem, let me briefly descript it. I am working to implement virtgpu S3 function on Xen.
Currently on Xen, if we start a guest through qemu with enabling virtgpu, and then suspend and resume guest. We can find that the guest kernel comes back, but the display doesn't. It just shown a black

screen.

Quoted 9 lines
Quoted 9 lines

That is because during suspending, guest called into qemu and qemu destroyed all display resources and reset renderer. This made the display gone after guest resumed.
So, I add a new command for virtio-gpu that when guest is suspending, it will notify qemu and set parameter(preserver_resource) to 1 and then qemu will preserve resources, and when resuming, guest will notify qemu to set parameter to 0, and then qemu will keep the normal actions. That can help guest's display come back.
When I upstream above implementation, Parav and MST suggest me to

use

Quoted 13 lines
Quoted 13 lines

the PM capability to fix this problem instead of adding a new command or state bit.
Now, I have tried the PM capability of virtio-gpu, it can't be used to solve this problem.
The reason is:
during guest suspending, it will write D3 state through PM cap, then I can save the resources of virtio-gpu on Qemu side(set preserver_resource to 1), but during the process of resuming, the state of PM cap will be cleared by qemu resetting(qemu_system_wakeup-> qemu_devices_reset-> virtio_vga_base_reset-> virtio_gpu_gl_reset), it causes that when guest reads state from PM cap, it will find the virtio-gpu has already been D0 state,

Quoted 4 lines
Quoted 1 line

This behavior needs to be fixed. As the spec listed out, " This 2-bit field is

used both to determine the current power state of a Function" Do you mean it is wrong to reset PM cap when vritio_gpu reset in current qemu code? Why?

Because PM is implementing the support from D3->d0 transition and if it device in D3, the device needs to respond that it is in D3 to match the PCI spec.

Quoted 2 lines

Shouldn't all device states, including PM registers, be reset during the process of virtio-gpu reset?

If No_Soft_Reset== 0, no device context to be preserved.
If No_Soft_Reset == 1, device to preserve minimal registers and other things listed in pci spec.

Quoted 6 lines
Quoted 3 lines

So device needs to return D3 in the PowerState field. This is must.

But current behavior is a kind of soft reset, I think(!PCI_PM_CTRL_NO_SOFT_RESET). The pm cap is reset by qemu is reasonable.

Quoted 6 lines

What you described is, you need to do No_Soft_Reset=1, so please set the cap accordingly to achieve the restore.

Also in your case the if the QEMU knows that it will have to resume the device soon. Hence, it can well prepare the gpu context before resuming the vcpus. In such case, the extra register wouldn’t be necessary.
Having PM control register is anyway needed to drive the device properly.

Even as you said, the reset behavior of PM in the current QEMU code is incorrect, and even if it is modified, it also cannot fix this problem with S3.
Because there is twice device reset during resuming.
First is when we trigger a resume command to qemu, qemu will reset device(qemu_system_wakeup-> qemu_devices_reset-> virtio_vga_base_reset-> virtio_gpu_gl_reset).
After the first time, then second time happens in guest kernel, virtio_device_restore-> virtio_reset_device. But the PM state changes (D3 to D0) happens between those two, so the display resources will be still destroyed by the second time of device reset. The most feasible and useful way to fix this problem is that just need to add a new virtio-gpu command instead of an extra register or using PM cap.
Thanks.

Quoted 245 lines

Having the extra busy_poll register is flexible. So please evaluate if you need it or not.

Quoted 242 lines
Quoted 3 lines

In addition to it, an additional busy_poll register is helpful that indicates the

device is ready to use.

Quoted 2 lines

This is because 10msec is the timeout set by the PCI spec.
This can be hard for the devices to implement if the large GPU state is being

read from files or slow media or for other hw devices in large quantities.

Quoted 4 lines

This limit comes from the PCI spec normative of below.

After transitioning a VF from D3Hot to D0, at least one of the following is

true:

Quoted 5 lines

◦ At least 10 ms has passed since the request to enter D0 was issued.

So Readiness Time Reporting capability is not so useful.

Hence, after PM state to D3->D0 transition is successful, virtio level PCI

register is useful to ensure that device is resumed to drive rest of the registers.

Quoted 7 lines
Quoted 7 lines

so
guest will not write D0 through PM cap, so I can't know when to restore the resources(set preserver_resource to 0).
Do you have any other suggestions?
Or can I just fallback to the version that add a new command(VIRTIO_GPU_CMD_PRESERVE_RESOURCE) in virtio-gpu? I think

that

Quoted 28 lines
Quoted 28 lines

way is more reasonable and feasible for virtio-gpu to protect display resources during S3. As for other devices, if necessary, they can also refer to the implementation of the virtio-gpu to add new commands to prevent resource loss during S3.

Quoted 22 lines · Jiqian

Hi Michael S. Tsirkin and Parav Pandit, Thank you for your detailed explanation. I will try to use PM cap to fix this issue.

Quoted 18 lines · Michael S. Tsirkin
Quoted 17 lines · Jiqian
Quoted 15 lines · Parav Pandit
Quoted 15 lines

From: Chen, Jiqian <[email protected]>
Sent: Tuesday, October 24, 2023 5:44 PM

Quoted 9 lines · Parav Pandit
Quoted 9 lines

From: Chen, Jiqian <[email protected]>
Sent: Tuesday, October 24, 2023 4:06 PM

Quoted 4 lines · Parav Pandit
Quoted 3 lines

From: Chen, Jiqian <[email protected]>
Sent: Monday, October 23, 2023 4:09 PM

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
Quoted 5 lines

I think this can be done without introducing the new register.
Can you please check if the PM register itself can serve
the purpose instead
of new virtio level register?
Do you mean the system PM register?

No, the device's PM register at transport level.

I tried to find this register(pci level or virtio pci level or virtio driver level), but I didn't find it in Linux kernel or Qemu

codes.

Quoted 10 lines
Quoted 10 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines

May I know which register you are referring to specifically? Or which PM state bit you mentioned below?

PCI spec's PCI Power Management Capability Structure in section

7.5.2.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Yes, what you point to is PM capability for PCIe device. But the problem is still that in Qemu code, it will check the condition(pci_bus_is_express or pci_is_express) of all virtio-pci devices in function virtio_pci_realize(), if the virtio devices aren't a PCIe device, it will not add PM capability for

them.

Quoted 13 lines
Quoted 13 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

PCI PM capability is must for PCIe devices. So may be QEMU code has put

it only under is_pcie check.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

But it can be done outside of that check as well because this capability

exists on PCI too for long time and it is backward compatible.

Quoted 7 lines
Quoted 7 lines
Quoted 3 lines

Do you suggest me to implement PM capability for virtio devices in Qemu firstly, and then to try if the PM capability can work for this scenario?

virtio devices in qemu already have a PM capability.

Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

If so, we will complicate a simple problem. Because there are no other

needs to add PM capability for virtio devices for now, if we add it just for preserving resources, it seems unnecessary and unreasonable. And we are not sure if there are other scenarios that are not during the process of PM state changing also need to preserve resources, if have, then the PM register can't cover, but preserve_resources register

can.

Quoted 11 lines
Quoted 11 lines
Quoted 8 lines
Quoted 8 lines

One of the selling points of virtio is precisely reusing existing platform capabilities as opposed to coming up with our own. See abstract.tex

Quoted 2 lines

Can I add some notes like "If PM capability is implemented for virtio

devices, it may cover this scenario, and if there are no other scenarios that PM can't cover, then we can remove this register " in commit message or spec description and let us continue to add

preserve_resources register?

Quoted 42 lines
Quoted 42 lines
Quoted 8 lines
Quoted 8 lines

We can't remove registers.

Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

And another problem is how about the MMIO transport devices? Since preserve resources is need for all transport type devices.

MMIO lacks such rich PM definitions. If in future MMIO wants to

support, it will be extended to match to other transports like PCI.

Quoted 33 lines
Quoted 33 lines
Quoted 33 lines
Quoted 33 lines
Quoted 33 lines
Quoted 10 lines
Quoted 9 lines
Quoted 6 lines
Quoted 4 lines

I think it is unreasonable to let virtio- device listen the
PM state of Guest system.

Guest driver performs any work on the guest systems PM callback events in

the virtio driver.
I didn't find any PM state callback in the virtio driver.

There are virtio_suspend and virtio_resume in case of Linux.

I think what you said virtio_suspend/resume is freeze/restore callback from "struct virtio_driver" or suspend/resume callback from "static const struct dev_pm_ops virtio_pci_pm_ops". And yes, I agree, if virtio devices have PM capability, maybe we can set PM state in those callback functions.

Quoted 11 lines
Quoted 11 lines
Quoted 7 lines
Quoted 4 lines

It's more suitable that each device gets notifications from
driver, and then do preserving resources operation.

I agree that each device gets the notification from driver. The question is, should it be virtio driver, or existing pci driver which

transitions the state from d0->d3 and d3->d0 is enough. It seems there isn't existing pci driver to transitions d0 or d3 state. Could you please tell me which one it is specifically? I am very willing to

give a try.

Quoted 2 lines
Quoted 1 line

Virtio-pci modern driver of Linux should be able to.

Yes, I know, it is the VIRTIO_PCI_FLAG_INIT_PM_BIT. But still the two problems I said above.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

Both can be resolved without switching to pcie.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

Can you please check that?

Quoted 3 lines

--- a/transport-pci.tex
+++ b/transport-pci.tex
@@ -325,6 +325,7 @@ \subsubsection{Common

configuration

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

structure

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

layout}\label{sec:Virtio Transport
/* About the administration virtqueue. */
le16 admin_queue_index; /* read-only for driver

*/

Quoted 22 lines
Quoted 22 lines
Quoted 22 lines
Quoted 22 lines
Quoted 22 lines
Quoted 22 lines
Quoted 22 lines
Quoted 22 lines
Quoted 22 lines
Quoted 22 lines
Quoted 22 lines

le16 admin_queue_num; /* read-only for driver */
+ le16 preserve_resources; /* read-write */
Preserving these resources in the device implementation
takes finite amount
of time.
Possibly more than 40nsec (time of PCIe write TLP).
Hence this register must be a polling register to indicate
that
preservation_done.
This will tell the guest when the preservation is done, and
when restoration is
done, so that it can resume upper layers.

Please refer to queue_reset definition to learn more about
such register
definition.
Thanks, I will refer to "queue_reset". So, I need three
values, driver write 1 to let device do preserving
resources, driver write
2 to let device do restoring resources, device write 0 to
tell driver that preserving or restoring done, am I right?

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Right.

And if the existing pcie pm state bits can do, we can leverage

that.

Quoted 45 lines
Quoted 45 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 2 lines

If it cannot be used, lets add that reasoning in the commit log to describe this

register.

Quoted 9 lines
Quoted 9 lines

Lets please make sure that PCIe PM level registers are
sufficient/not-sufficient
to decide the addition of this register.
But if the device is not a PCIe device, it doesn't have PM
capability, then this will not work. Actually in my local
environment, pci_is_express() return false in Qemu, they are
not PCIe

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

device.

Quoted 3 lines

It is reasonable to ask to plug in as PCIe device in 2023 to get new functionality that too you mentioned a gpu device. 😊 Which does not have very long history of any backward

compatibility.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

Do you suggest me to add PM capability for virtio-gpu or change virtio-gpu to a PCIe device?

PCI Power Management Capability Structure does not seem to be limited to

PCIe.
I am not sure, but in current Qemu code, I can see the check

"pci_is_express"

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

for all virtio-pci devices. If we want to add PM capability for virtio-pci devices, we need to change them to PCIe device I think.

That is one option.
Second option to extend PCI PM cap for non pci device because it is

supported.

Quoted 12 lines
Quoted 11 lines
Quoted 10 lines
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

--
Best regards,
Jiqian Chen.

--
Best regards,
Jiqian Chen.

Quoted 3 lines
Quoted 3 lines

--
Best regards,
Jiqian Chen.

--
Best regards,
Jiqian Chen.

Signature · 2 lines
Best regards,
Jiqian Chen.
#17 lore raw

[virtio-comment] RE: [PATCH v6 1/1] content: Add new feature VIRTIO_F_PRESERVE_RESOURCES

Quoted 77 lines

From: Chen, Jiqian <[email protected]>
Sent: Friday, January 12, 2024 2:55 PM

Quoted 9 lines · Parav Pandit
Quoted 9 lines

From: Chen, Jiqian <[email protected]>
Sent: Friday, January 12, 2024 1:55 PM

Quoted 2 lines · Parav Pandit

Hi Jiqian,

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

From: Chen, Jiqian <[email protected]>
Sent: Friday, January 12, 2024 1:11 PM

Hi all,
Sorry to reply late.
I don't know if you still remember this problem, let me briefly descript

it.

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Quoted 5 lines

I am working to implement virtgpu S3 function on Xen. Currently on Xen, if we start a guest through qemu with enabling virtgpu, and then suspend and resume guest. We can find that the guest kernel comes back, but the display doesn't. It just shown a black

screen.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

That is because during suspending, guest called into qemu and qemu destroyed all display resources and reset renderer. This made the display gone after guest resumed.
So, I add a new command for virtio-gpu that when guest is suspending, it will notify qemu and set parameter(preserver_resource) to 1 and then qemu will preserve resources, and when resuming, guest will notify qemu to set parameter to 0, and then qemu will keep the normal actions. That can

help guest's display come back.

Quoted 15 lines
Quoted 15 lines
Quoted 1 line
Quoted 1 line

When I upstream above implementation, Parav and MST suggest me to

use

Quoted 13 lines
Quoted 13 lines

the PM capability to fix this problem instead of adding a new command or state bit.
Now, I have tried the PM capability of virtio-gpu, it can't be used to solve this problem.
The reason is:
during guest suspending, it will write D3 state through PM cap, then I can save the resources of virtio-gpu on Qemu side(set preserver_resource to 1), but during the process of resuming, the state of PM cap will be cleared by qemu resetting(qemu_system_wakeup-> qemu_devices_reset-> virtio_vga_base_reset-> virtio_gpu_gl_reset), it causes that when guest reads state from PM cap, it will find the virtio-gpu has already been D0 state,

Quoted 6 lines
Quoted 5 lines
Quoted 2 lines

This behavior needs to be fixed. As the spec listed out, " This 2-bit field is

used both to determine the current power state of a Function" Do you mean it is wrong to reset PM cap when vritio_gpu reset in current qemu code? Why?

Because PM is implementing the support from D3->d0 transition and if it

device in D3, the device needs to respond that it is in D3 to match the PCI spec.

Quoted 5 lines
Quoted 3 lines

Shouldn't all device states, including PM registers, be reset during the process of virtio-gpu reset?

If No_Soft_Reset== 0, no device context to be preserved. If No_Soft_Reset == 1, device to preserve minimal registers and other

things listed in pci spec.

Quoted 8 lines
Quoted 7 lines
Quoted 4 lines

So device needs to return D3 in the PowerState field. This is must.

But current behavior is a kind of soft reset, I think(!PCI_PM_CTRL_NO_SOFT_RESET). The pm cap is reset by qemu is reasonable.

What you described is, you need to do No_Soft_Reset=1, so please set the

cap accordingly to achieve the restore.

Quoted 1 line
Quoted 7 lines
Quoted 1 line

Also in your case the if the QEMU knows that it will have to resume the

device soon.

Quoted 3 lines

Hence, it can well prepare the gpu context before resuming the vcpus. In such case, the extra register wouldn’t be necessary. Having PM control register is anyway needed to drive the device properly.

Even as you said, the reset behavior of PM in the current QEMU code is incorrect, and even if it is modified, it also cannot fix this problem with S3.

You meant D3?

Quoted 4 lines

Because there is twice device reset during resuming. First is when we trigger a resume command to qemu, qemu will reset device(qemu_system_wakeup-> qemu_devices_reset-> virtio_vga_base_reset-> virtio_gpu_gl_reset).

A device implementation that supports PM should not reset the device. Please fix it.

Quoted 4 lines

After the first time, then second time happens in guest kernel, virtio_device_restore-> virtio_reset_device. But the PM state changes (D3 to D0) happens between those two, so the display resources will be still destroyed by the second time of device reset.

The driver that understands that device supports PM, will skip the reset steps. Hence the 2nd reset will also not occur.
Therefore, device state will be restored.

#18 lore raw

[virtio-comment] Re: [PATCH v6 1/1] content: Add new feature VIRTIO_F_PRESERVE_RESOURCES

Quoted 84 lines · Parav Pandit
Quoted 77 lines

From: Chen, Jiqian <[email protected]>
Sent: Friday, January 12, 2024 2:55 PM

Quoted 9 lines · Parav Pandit
Quoted 9 lines

From: Chen, Jiqian <[email protected]>
Sent: Friday, January 12, 2024 1:55 PM

Quoted 2 lines · Parav Pandit

Hi Jiqian,

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

From: Chen, Jiqian <[email protected]>
Sent: Friday, January 12, 2024 1:11 PM

Hi all,
Sorry to reply late.
I don't know if you still remember this problem, let me briefly descript

it.

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Quoted 5 lines

I am working to implement virtgpu S3 function on Xen. Currently on Xen, if we start a guest through qemu with enabling virtgpu, and then suspend and resume guest. We can find that the guest kernel comes back, but the display doesn't. It just shown a black

screen.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

That is because during suspending, guest called into qemu and qemu destroyed all display resources and reset renderer. This made the display gone after guest resumed.
So, I add a new command for virtio-gpu that when guest is suspending, it will notify qemu and set parameter(preserver_resource) to 1 and then qemu will preserve resources, and when resuming, guest will notify qemu to set parameter to 0, and then qemu will keep the normal actions. That can

help guest's display come back.

Quoted 15 lines
Quoted 15 lines
Quoted 1 line
Quoted 1 line

When I upstream above implementation, Parav and MST suggest me to

use

Quoted 13 lines
Quoted 13 lines

the PM capability to fix this problem instead of adding a new command or state bit.
Now, I have tried the PM capability of virtio-gpu, it can't be used to solve this problem.
The reason is:
during guest suspending, it will write D3 state through PM cap, then I can save the resources of virtio-gpu on Qemu side(set preserver_resource to 1), but during the process of resuming, the state of PM cap will be cleared by qemu resetting(qemu_system_wakeup-> qemu_devices_reset-> virtio_vga_base_reset-> virtio_gpu_gl_reset), it causes that when guest reads state from PM cap, it will find the virtio-gpu has already been D0 state,

Quoted 6 lines
Quoted 5 lines
Quoted 2 lines

This behavior needs to be fixed. As the spec listed out, " This 2-bit field is

used both to determine the current power state of a Function" Do you mean it is wrong to reset PM cap when vritio_gpu reset in current qemu code? Why?

Because PM is implementing the support from D3->d0 transition and if it

device in D3, the device needs to respond that it is in D3 to match the PCI spec.

Quoted 5 lines
Quoted 3 lines

Shouldn't all device states, including PM registers, be reset during the process of virtio-gpu reset?

If No_Soft_Reset== 0, no device context to be preserved. If No_Soft_Reset == 1, device to preserve minimal registers and other

things listed in pci spec.

Quoted 8 lines
Quoted 7 lines
Quoted 4 lines

So device needs to return D3 in the PowerState field. This is must.

But current behavior is a kind of soft reset, I think(!PCI_PM_CTRL_NO_SOFT_RESET). The pm cap is reset by qemu is reasonable.

What you described is, you need to do No_Soft_Reset=1, so please set the

cap accordingly to achieve the restore.

Quoted 1 line
Quoted 7 lines
Quoted 1 line

Also in your case the if the QEMU knows that it will have to resume the

device soon.

Quoted 3 lines

Hence, it can well prepare the gpu context before resuming the vcpus. In such case, the extra register wouldn’t be necessary. Having PM control register is anyway needed to drive the device properly.

Even as you said, the reset behavior of PM in the current QEMU code is incorrect, and even if it is modified, it also cannot fix this problem with S3.

Quoted 7 lines

You meant D3?

Quoted 4 lines

Because there is twice device reset during resuming. First is when we trigger a resume command to qemu, qemu will reset device(qemu_system_wakeup-> qemu_devices_reset-> virtio_vga_base_reset-> virtio_gpu_gl_reset).

A device implementation that supports PM should not reset the device. Please fix it.

Do you mean the devices_reset behavior of qemu shouldn't happen when a device has PM cap? Or just the state of PM cap shouldn't be reset?

Quoted 6 lines
Quoted 5 lines

After the first time, then second time happens in guest kernel, virtio_device_restore-> virtio_reset_device. But the PM state changes (D3 to D0) happens between those two, so the display resources will be still destroyed by the second time of device reset.

The driver that understands that device supports PM, will skip the reset steps.

But it happens for now.
In current qemu codes, the bit PCI_PM_CTRL_NO_SOFT_RESET of virtio-pci devices isn't set, is it a bug? It means the no_soft_reset==0.

Quoted 2 lines

Hence the 2nd reset will also not occur.
Therefore, device state will be restored.

Signature · 2 lines
Best regards,
Jiqian Chen.
#19 lore raw

[virtio-comment] RE: [PATCH v6 1/1] content: Add new feature VIRTIO_F_PRESERVE_RESOURCES

Quoted 98 lines

From: Chen, Jiqian <[email protected]>
Sent: Monday, January 15, 2024 1:03 PM

Quoted 39 lines · Parav Pandit
Quoted 39 lines

From: Chen, Jiqian <[email protected]>
Sent: Friday, January 12, 2024 2:55 PM

Quoted 9 lines · Parav Pandit
Quoted 9 lines

From: Chen, Jiqian <[email protected]>
Sent: Friday, January 12, 2024 1:55 PM

Quoted 2 lines · Parav Pandit

Hi Jiqian,

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

From: Chen, Jiqian <[email protected]>
Sent: Friday, January 12, 2024 1:11 PM

Hi all,
Sorry to reply late.
I don't know if you still remember this problem, let me briefly descript

it.

Quoted 15 lines
Quoted 15 lines
Quoted 5 lines
Quoted 5 lines

I am working to implement virtgpu S3 function on Xen. Currently on Xen, if we start a guest through qemu with enabling virtgpu, and then suspend and resume guest. We can find that the guest kernel comes back, but the display doesn't. It just shown a black

screen.

Quoted 9 lines
Quoted 9 lines

That is because during suspending, guest called into qemu and qemu destroyed all display resources and reset renderer. This made the display gone after guest resumed.
So, I add a new command for virtio-gpu that when guest is suspending, it will notify qemu and set parameter(preserver_resource) to 1 and then qemu will preserve resources, and when resuming, guest will notify qemu to set parameter to 0, and then qemu will keep the normal actions. That can

Quoted 2 lines
Quoted 2 lines

help guest's display come back.

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

When I upstream above implementation, Parav and MST suggest me

to

Quoted 51 lines
Quoted 41 lines
Quoted 14 lines
Quoted 14 lines

use

Quoted 13 lines
Quoted 13 lines

the PM capability to fix this problem instead of adding a new command or state bit.
Now, I have tried the PM capability of virtio-gpu, it can't be used to solve this problem.
The reason is:
during guest suspending, it will write D3 state through PM cap, then I can save the resources of virtio-gpu on Qemu side(set preserver_resource to 1), but during the process of resuming, the state of PM cap will be cleared by qemu resetting(qemu_system_wakeup-> qemu_devices_reset-> virtio_vga_base_reset-> virtio_gpu_gl_reset), it causes that when guest reads state from PM cap, it will find the virtio-gpu has already been D0 state,

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

This behavior needs to be fixed. As the spec listed out, " This 2-bit field is

used both to determine the current power state of a Function" Do you mean it is wrong to reset PM cap when vritio_gpu reset in current qemu code? Why?

Because PM is implementing the support from D3->d0 transition and if it

device in D3, the device needs to respond that it is in D3 to match the PCI spec.

Quoted 6 lines
Quoted 3 lines

Shouldn't all device states, including PM registers, be reset during the process of virtio-gpu reset?

If No_Soft_Reset== 0, no device context to be preserved. If No_Soft_Reset == 1, device to preserve minimal registers and other

things listed in pci spec.

Quoted 9 lines
Quoted 7 lines
Quoted 4 lines

So device needs to return D3 in the PowerState field. This is must.

But current behavior is a kind of soft reset, I think(!PCI_PM_CTRL_NO_SOFT_RESET). The pm cap is reset by qemu is reasonable.

What you described is, you need to do No_Soft_Reset=1, so please set the

cap accordingly to achieve the restore.

Quoted 1 line
Quoted 8 lines
Quoted 2 lines

Also in your case the if the QEMU knows that it will have to resume the

device soon.

Quoted 3 lines

Hence, it can well prepare the gpu context before resuming the vcpus. In such case, the extra register wouldn’t be necessary. Having PM control register is anyway needed to drive the device properly.

Even as you said, the reset behavior of PM in the current QEMU code is incorrect, and even if it is modified, it also cannot fix this problem with S3.

You meant D3?

Quoted 8 lines
Quoted 5 lines
Quoted 4 lines

Because there is twice device reset during resuming. First is when we trigger a resume command to qemu, qemu will reset device(qemu_system_wakeup-> qemu_devices_reset-> virtio_vga_base_reset-> virtio_gpu_gl_reset).

A device implementation that supports PM should not reset the device.

Please fix it.
Do you mean the devices_reset behavior of qemu shouldn't happen when a device has PM cap?

Right. Device reset should not happen on PM capable device that offers no_soft_reset==1.

Quoted 11 lines

Or just the state of PM cap shouldn't be reset?

Quoted 7 lines
Quoted 6 lines

After the first time, then second time happens in guest kernel, virtio_device_restore-> virtio_reset_device. But the PM state changes (D3 to
D0) happens between those two, so the display resources will be still destroyed by the second time of device reset.

The driver that understands that device supports PM, will skip the reset

steps.
But it happens for now.

This should be enhanced in the guest driver.

Quoted 3 lines

In current qemu codes, the bit PCI_PM_CTRL_NO_SOFT_RESET of virtio-pci devices isn't set, is it a bug? It means the no_soft_reset==0.

It should be set when/if the device can store and restore the device context on d3->d0 transition.

Quoted 6 lines
Quoted 2 lines

Hence the 2nd reset will also not occur.
Therefore, device state will be restored.

--
Best regards,
Jiqian Chen.

#20 lore raw

Re: [virtio-comment] RE: [PATCH v6 1/1] content: Add new feature VIRTIO_F_PRESERVE_RESOURCES

Quoted 102 lines · Parav Pandit
Quoted 102 lines

From: Chen, Jiqian <[email protected]>
Sent: Monday, January 15, 2024 1:03 PM

Quoted 39 lines · Parav Pandit
Quoted 39 lines

From: Chen, Jiqian <[email protected]>
Sent: Friday, January 12, 2024 2:55 PM

Quoted 9 lines · Parav Pandit
Quoted 9 lines

From: Chen, Jiqian <[email protected]>
Sent: Friday, January 12, 2024 1:55 PM

Quoted 2 lines · Parav Pandit

Hi Jiqian,

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

From: Chen, Jiqian <[email protected]>
Sent: Friday, January 12, 2024 1:11 PM

Hi all,
Sorry to reply late.
I don't know if you still remember this problem, let me briefly descript

it.

Quoted 15 lines
Quoted 15 lines
Quoted 5 lines
Quoted 5 lines

I am working to implement virtgpu S3 function on Xen. Currently on Xen, if we start a guest through qemu with enabling virtgpu, and then suspend and resume guest. We can find that the guest kernel comes back, but the display doesn't. It just shown a black

screen.

Quoted 9 lines
Quoted 9 lines

That is because during suspending, guest called into qemu and qemu destroyed all display resources and reset renderer. This made the display gone after guest resumed.
So, I add a new command for virtio-gpu that when guest is suspending, it will notify qemu and set parameter(preserver_resource) to 1 and then qemu will preserve resources, and when resuming, guest will notify qemu to set parameter to 0, and then qemu will keep the normal actions. That can

Quoted 2 lines
Quoted 2 lines

help guest's display come back.

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

When I upstream above implementation, Parav and MST suggest me

to

Quoted 55 lines
Quoted 41 lines
Quoted 14 lines
Quoted 14 lines

use

Quoted 13 lines
Quoted 13 lines

the PM capability to fix this problem instead of adding a new command or state bit.
Now, I have tried the PM capability of virtio-gpu, it can't be used to solve this problem.
The reason is:
during guest suspending, it will write D3 state through PM cap, then I can save the resources of virtio-gpu on Qemu side(set preserver_resource to 1), but during the process of resuming, the state of PM cap will be cleared by qemu resetting(qemu_system_wakeup-> qemu_devices_reset-> virtio_vga_base_reset-> virtio_gpu_gl_reset), it causes that when guest reads state from PM cap, it will find the virtio-gpu has already been D0 state,

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

This behavior needs to be fixed. As the spec listed out, " This 2-bit field is

used both to determine the current power state of a Function" Do you mean it is wrong to reset PM cap when vritio_gpu reset in current qemu code? Why?

Because PM is implementing the support from D3->d0 transition and if it

device in D3, the device needs to respond that it is in D3 to match the PCI spec.

Quoted 6 lines
Quoted 3 lines

Shouldn't all device states, including PM registers, be reset during the process of virtio-gpu reset?

If No_Soft_Reset== 0, no device context to be preserved. If No_Soft_Reset == 1, device to preserve minimal registers and other

things listed in pci spec.

Quoted 9 lines
Quoted 7 lines
Quoted 4 lines

So device needs to return D3 in the PowerState field. This is must.

But current behavior is a kind of soft reset, I think(!PCI_PM_CTRL_NO_SOFT_RESET). The pm cap is reset by qemu is reasonable.

What you described is, you need to do No_Soft_Reset=1, so please set the

cap accordingly to achieve the restore.

Quoted 1 line
Quoted 8 lines
Quoted 2 lines

Also in your case the if the QEMU knows that it will have to resume the

device soon.

Quoted 3 lines

Hence, it can well prepare the gpu context before resuming the vcpus. In such case, the extra register wouldn’t be necessary. Having PM control register is anyway needed to drive the device properly.

Even as you said, the reset behavior of PM in the current QEMU code is incorrect, and even if it is modified, it also cannot fix this problem with S3.

You meant D3?

Quoted 4 lines

Because there is twice device reset during resuming. First is when we trigger a resume command to qemu, qemu will reset device(qemu_system_wakeup-> qemu_devices_reset-> virtio_vga_base_reset-> virtio_gpu_gl_reset).

Quoted 5 lines
Quoted 4 lines
Quoted 1 line

A device implementation that supports PM should not reset the device.

Please fix it.
Do you mean the devices_reset behavior of qemu shouldn't happen when a device has PM cap?

Right. Device reset should not happen on PM capable device that offers no_soft_reset==1.

But current qemu code, no_soft_reset==0.

Quoted 10 lines
Quoted 10 lines

Or just the state of PM cap shouldn't be reset?

Quoted 7 lines
Quoted 6 lines

After the first time, then second time happens in guest kernel, virtio_device_restore-> virtio_reset_device. But the PM state changes (D3 to
D0) happens between those two, so the display resources will be still destroyed by the second time of device reset.

The driver that understands that device supports PM, will skip the reset

Quoted 8 lines
Quoted 2 lines

steps.
But it happens for now.

This should be enhanced in the guest driver.

Quoted 3 lines

In current qemu codes, the bit PCI_PM_CTRL_NO_SOFT_RESET of virtio-pci devices isn't set, is it a bug? It means the no_soft_reset==0.

It should be set when/if the device can store and restore the device context on d3->d0 transition.

I don't know why it doesn't be set in current qemu code.
What do you mean "the device can store and restore the device context on d3->d0 transition"? The real physical device or the simulated devices on qemu side? How do I confirm it?

Quoted 7 lines
Quoted 7 lines
Quoted 3 lines

Hence the 2nd reset will also not occur.
Therefore, device state will be restored.

--
Best regards,
Jiqian Chen.

Signature · 2 lines
Best regards,
Jiqian Chen.
#21 lore raw

RE: [virtio-comment] RE: [PATCH v6 1/1] content: Add new feature VIRTIO_F_PRESERVE_RESOURCES

Quoted 110 lines

From: Chen, Jiqian <[email protected]>
Sent: Monday, January 15, 2024 1:18 PM

Quoted 76 lines · Parav Pandit
Quoted 76 lines

From: Chen, Jiqian <[email protected]>
Sent: Monday, January 15, 2024 1:03 PM

Quoted 39 lines · Parav Pandit
Quoted 39 lines

From: Chen, Jiqian <[email protected]>
Sent: Friday, January 12, 2024 2:55 PM

Quoted 9 lines · Parav Pandit
Quoted 9 lines

From: Chen, Jiqian <[email protected]>
Sent: Friday, January 12, 2024 1:55 PM

Quoted 2 lines · Parav Pandit

Hi Jiqian,

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

From: Chen, Jiqian <[email protected]>
Sent: Friday, January 12, 2024 1:11 PM

Hi all,
Sorry to reply late.
I don't know if you still remember this problem, let me briefly descript

it.

Quoted 15 lines
Quoted 15 lines
Quoted 5 lines
Quoted 5 lines

I am working to implement virtgpu S3 function on Xen. Currently on Xen, if we start a guest through qemu with enabling virtgpu, and then suspend and resume guest. We can find that the guest kernel comes back, but the display doesn't. It just shown a black

screen.

Quoted 9 lines
Quoted 9 lines

That is because during suspending, guest called into qemu and qemu destroyed all display resources and reset renderer. This made the display gone after guest resumed.
So, I add a new command for virtio-gpu that when guest is suspending, it will notify qemu and set parameter(preserver_resource) to 1 and then qemu will preserve resources, and when resuming, guest will notify qemu to set parameter to 0, and then qemu will keep the normal actions. That can

Quoted 2 lines
Quoted 2 lines

help guest's display come back.

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

When I upstream above implementation, Parav and MST suggest me

to

Quoted 29 lines
Quoted 29 lines
Quoted 14 lines
Quoted 14 lines

use

Quoted 13 lines
Quoted 13 lines

the PM capability to fix this problem instead of adding a new command or state bit.
Now, I have tried the PM capability of virtio-gpu, it can't be used to solve this problem.
The reason is:
during guest suspending, it will write D3 state through PM cap, then I can save the resources of virtio-gpu on Qemu side(set preserver_resource to 1), but during the process of resuming, the state of PM cap will be cleared by qemu resetting(qemu_system_wakeup-> qemu_devices_reset-> virtio_vga_base_reset-> virtio_gpu_gl_reset), it causes that when guest reads state from PM cap, it will find the virtio-gpu has already been D0 state,

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

This behavior needs to be fixed. As the spec listed out, " This 2-bit field is

used both to determine the current power state of a Function" Do you mean it is wrong to reset PM cap when vritio_gpu reset in current qemu code? Why?

Because PM is implementing the support from D3->d0 transition and if it

device in D3, the device needs to respond that it is in D3 to match the PCI spec.

Quoted 6 lines
Quoted 3 lines

Shouldn't all device states, including PM registers, be reset during the process of virtio-gpu reset?

If No_Soft_Reset== 0, no device context to be preserved. If No_Soft_Reset == 1, device to preserve minimal registers and other

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

things listed in pci spec.

Quoted 6 lines
Quoted 6 lines
Quoted 4 lines

So device needs to return D3 in the PowerState field. This is must.

But current behavior is a kind of soft reset, I think(!PCI_PM_CTRL_NO_SOFT_RESET). The pm cap is reset by qemu

is

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 3 lines
Quoted 1 line

reasonable.

What you described is, you need to do No_Soft_Reset=1, so please set the

cap accordingly to achieve the restore.

Quoted 3 lines

Also in your case the if the QEMU knows that it will have to resume the

device soon.

Quoted 3 lines

Hence, it can well prepare the gpu context before resuming the vcpus. In such case, the extra register wouldn’t be necessary. Having PM control register is anyway needed to drive the device

properly.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Even as you said, the reset behavior of PM in the current QEMU code is incorrect, and even if it is modified, it also cannot fix this problem with

S3.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

You meant D3?

Quoted 4 lines

Because there is twice device reset during resuming. First is when we trigger a resume command to qemu, qemu will reset device(qemu_system_wakeup-> qemu_devices_reset-> virtio_vga_base_reset-> virtio_gpu_gl_reset).

Quoted 8 lines
Quoted 5 lines
Quoted 4 lines
Quoted 1 line

A device implementation that supports PM should not reset the device.

Please fix it.
Do you mean the devices_reset behavior of qemu shouldn't happen when a device has PM cap?

Right. Device reset should not happen on PM capable device that offers

no_soft_reset==1.
But current qemu code, no_soft_reset==0.

So please fix the qemu when you are adding the functionality of restoring the device context on PM.

Quoted 14 lines
Quoted 14 lines
Quoted 14 lines

Or just the state of PM cap shouldn't be reset?

Quoted 9 lines
Quoted 7 lines

After the first time, then second time happens in guest kernel, virtio_device_restore-> virtio_reset_device. But the PM state changes
(D3 to
D0) happens between those two, so the display resources will be still destroyed by the second time of device reset.

The driver that understands that device supports PM, will skip the reset

steps.
But it happens for now.

Quoted 8 lines
Quoted 6 lines

This should be enhanced in the guest driver.

Quoted 3 lines

In current qemu codes, the bit PCI_PM_CTRL_NO_SOFT_RESET of virtio-pci devices isn't set, is it a bug? It means the no_soft_reset==0.

It should be set when/if the device can store and restore the device context

on d3->d0 transition.
I don't know why it doesn't be set in current qemu code.

May be because QEMU is not restoring the context on PM commands.

Quoted 3 lines

What do you mean "the device can store and restore the device context on d3->d0 transition"? The real physical device or the simulated devices on qemu side?

Does not matter, whichever implementation of device is doing the PM should set it. In your case it is qemu.

Quoted 1 line

How do I confirm it?

If you mean "I" means guest driver, it will just work as long as it refers to the PM capabilities.

Quoted 12 lines
Quoted 8 lines
Quoted 8 lines
Quoted 4 lines

Hence the 2nd reset will also not occur.
Therefore, device state will be restored.

--
Best regards,
Jiqian Chen.

--
Best regards,
Jiqian Chen.

#22 lore raw

Re: [virtio-comment] RE: [PATCH v6 1/1] content: Add new feature VIRTIO_F_PRESERVE_RESOURCES

Quoted 111 lines · Parav Pandit
Quoted 111 lines

From: Chen, Jiqian <[email protected]>
Sent: Monday, January 15, 2024 1:18 PM

Quoted 76 lines · Parav Pandit
Quoted 76 lines

From: Chen, Jiqian <[email protected]>
Sent: Monday, January 15, 2024 1:03 PM

Quoted 39 lines · Parav Pandit
Quoted 39 lines

From: Chen, Jiqian <[email protected]>
Sent: Friday, January 12, 2024 2:55 PM

Quoted 9 lines · Parav Pandit
Quoted 9 lines

From: Chen, Jiqian <[email protected]>
Sent: Friday, January 12, 2024 1:55 PM

Quoted 2 lines · Parav Pandit

Hi Jiqian,

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

From: Chen, Jiqian <[email protected]>
Sent: Friday, January 12, 2024 1:11 PM

Hi all,
Sorry to reply late.
I don't know if you still remember this problem, let me briefly descript

it.

Quoted 15 lines
Quoted 15 lines
Quoted 5 lines
Quoted 5 lines

I am working to implement virtgpu S3 function on Xen. Currently on Xen, if we start a guest through qemu with enabling virtgpu, and then suspend and resume guest. We can find that the guest kernel comes back, but the display doesn't. It just shown a black

screen.

Quoted 9 lines
Quoted 9 lines

That is because during suspending, guest called into qemu and qemu destroyed all display resources and reset renderer. This made the display gone after guest resumed.
So, I add a new command for virtio-gpu that when guest is suspending, it will notify qemu and set parameter(preserver_resource) to 1 and then qemu will preserve resources, and when resuming, guest will notify qemu to set parameter to 0, and then qemu will keep the normal actions. That can

Quoted 2 lines
Quoted 2 lines

help guest's display come back.

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

When I upstream above implementation, Parav and MST suggest me

to

Quoted 29 lines
Quoted 29 lines
Quoted 14 lines
Quoted 14 lines

use

Quoted 13 lines
Quoted 13 lines

the PM capability to fix this problem instead of adding a new command or state bit.
Now, I have tried the PM capability of virtio-gpu, it can't be used to solve this problem.
The reason is:
during guest suspending, it will write D3 state through PM cap, then I can save the resources of virtio-gpu on Qemu side(set preserver_resource to 1), but during the process of resuming, the state of PM cap will be cleared by qemu resetting(qemu_system_wakeup-> qemu_devices_reset-> virtio_vga_base_reset-> virtio_gpu_gl_reset), it causes that when guest reads state from PM cap, it will find the virtio-gpu has already been D0 state,

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

This behavior needs to be fixed. As the spec listed out, " This 2-bit field is

used both to determine the current power state of a Function" Do you mean it is wrong to reset PM cap when vritio_gpu reset in current qemu code? Why?

Because PM is implementing the support from D3->d0 transition and if it

device in D3, the device needs to respond that it is in D3 to match the PCI spec.

Quoted 6 lines
Quoted 3 lines

Shouldn't all device states, including PM registers, be reset during the process of virtio-gpu reset?

If No_Soft_Reset== 0, no device context to be preserved. If No_Soft_Reset == 1, device to preserve minimal registers and other

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

things listed in pci spec.

Quoted 6 lines
Quoted 6 lines
Quoted 4 lines

So device needs to return D3 in the PowerState field. This is must.

But current behavior is a kind of soft reset, I think(!PCI_PM_CTRL_NO_SOFT_RESET). The pm cap is reset by qemu

is

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 3 lines
Quoted 1 line

reasonable.

What you described is, you need to do No_Soft_Reset=1, so please set the

cap accordingly to achieve the restore.

Quoted 3 lines

Also in your case the if the QEMU knows that it will have to resume the

device soon.

Quoted 3 lines

Hence, it can well prepare the gpu context before resuming the vcpus. In such case, the extra register wouldn’t be necessary. Having PM control register is anyway needed to drive the device

properly.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Even as you said, the reset behavior of PM in the current QEMU code is incorrect, and even if it is modified, it also cannot fix this problem with

S3.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

You meant D3?

Quoted 4 lines

Because there is twice device reset during resuming. First is when we trigger a resume command to qemu, qemu will reset device(qemu_system_wakeup-> qemu_devices_reset-> virtio_vga_base_reset-> virtio_gpu_gl_reset).

A device implementation that supports PM should not reset the device.

Quoted 8 lines
Quoted 7 lines
Quoted 4 lines
Quoted 3 lines

Please fix it.
Do you mean the devices_reset behavior of qemu shouldn't happen when a device has PM cap?

Right. Device reset should not happen on PM capable device that offers

no_soft_reset==1.
But current qemu code, no_soft_reset==0.

So please fix the qemu when you are adding the functionality of restoring the device context on PM.

My patch didn't add the functionality of restoring the device context on PM.
Is no_soft_reset must set 1 when a device has PM cap? It should also be allowed for situations that are not equal to 1, right?
There should be devices that has PM cap but no_soft_reset is 0 because that devices can't store and restore the device context on d3->d0 transition, like current qemu code. So the fix should be feasible for all situations that whether the no_soft_reset is 1 or not.
If use PM cap, not every situation can solve current problem (display resources of GPU will be destroyed).

Quoted 46 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines

Or just the state of PM cap shouldn't be reset?

Quoted 9 lines
Quoted 7 lines

After the first time, then second time happens in guest kernel, virtio_device_restore-> virtio_reset_device. But the PM state changes
(D3 to
D0) happens between those two, so the display resources will be still destroyed by the second time of device reset.

The driver that understands that device supports PM, will skip the reset

steps.
But it happens for now.

Quoted 8 lines
Quoted 6 lines

This should be enhanced in the guest driver.

Quoted 3 lines

In current qemu codes, the bit PCI_PM_CTRL_NO_SOFT_RESET of virtio-pci devices isn't set, is it a bug? It means the no_soft_reset==0.

It should be set when/if the device can store and restore the device context

on d3->d0 transition.
I don't know why it doesn't be set in current qemu code.

May be because QEMU is not restoring the context on PM commands.

Quoted 3 lines

What do you mean "the device can store and restore the device context on d3->d0 transition"? The real physical device or the simulated devices on qemu side?

Does not matter, whichever implementation of device is doing the PM should set it. In your case it is qemu.

Quoted 1 line

How do I confirm it?

If you mean "I" means guest driver, it will just work as long as it refers to the PM capabilities.

Quoted 12 lines
Quoted 8 lines
Quoted 8 lines
Quoted 4 lines

Hence the 2nd reset will also not occur.
Therefore, device state will be restored.

--
Best regards,
Jiqian Chen.

--
Best regards,
Jiqian Chen.

Signature · 2 lines
Best regards,
Jiqian Chen.
#23 lore raw

RE: [virtio-comment] RE: [PATCH v6 1/1] content: Add new feature VIRTIO_F_PRESERVE_RESOURCES

Quoted 125 lines

From: Chen, Jiqian <[email protected]>
Sent: Monday, January 15, 2024 1:51 PM

Quoted 40 lines · Parav Pandit
Quoted 40 lines

From: Chen, Jiqian <[email protected]>
Sent: Monday, January 15, 2024 1:18 PM

Quoted 35 lines · Parav Pandit
Quoted 35 lines

From: Chen, Jiqian <[email protected]>
Sent: Monday, January 15, 2024 1:03 PM

Quoted 30 lines · Parav Pandit
Quoted 30 lines

From: Chen, Jiqian <[email protected]>
Sent: Friday, January 12, 2024 2:55 PM

Quoted 9 lines · Parav Pandit
Quoted 9 lines

From: Chen, Jiqian <[email protected]>
Sent: Friday, January 12, 2024 1:55 PM

Quoted 2 lines · Parav Pandit

Hi Jiqian,

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

From: Chen, Jiqian <[email protected]>
Sent: Friday, January 12, 2024 1:11 PM

Hi all,
Sorry to reply late.
I don't know if you still remember this problem, let me briefly descript

it.

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Quoted 5 lines

I am working to implement virtgpu S3 function on Xen. Currently on Xen, if we start a guest through qemu with enabling virtgpu, and then suspend and resume guest. We can find that the guest kernel comes back, but the display doesn't. It just shown a black

screen.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

That is because during suspending, guest called into qemu and qemu destroyed all display resources and reset renderer. This made the display gone after guest resumed.
So, I add a new command for virtio-gpu that when guest is suspending, it will notify qemu and set parameter(preserver_resource) to 1 and then qemu will preserve resources, and when resuming, guest will notify qemu to set parameter to 0, and then qemu will keep the normal

actions.

Quoted 34 lines
Quoted 34 lines
Quoted 34 lines
Quoted 34 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

That can

help guest's display come back.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

When I upstream above implementation, Parav and MST suggest me

to

Quoted 29 lines
Quoted 29 lines
Quoted 14 lines
Quoted 14 lines

use

Quoted 13 lines
Quoted 13 lines

the PM capability to fix this problem instead of adding a new command or state bit.
Now, I have tried the PM capability of virtio-gpu, it can't be used to solve this problem.
The reason is:
during guest suspending, it will write D3 state through PM cap, then I can save the resources of virtio-gpu on Qemu side(set preserver_resource to 1), but during the process of resuming, the state of PM cap will be cleared by qemu resetting(qemu_system_wakeup-> qemu_devices_reset-> virtio_vga_base_reset-> virtio_gpu_gl_reset), it causes that when guest reads state from PM cap, it will find the virtio-gpu has already been D0 state,

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

This behavior needs to be fixed. As the spec listed out, " This 2-bit field is

used both to determine the current power state of a Function" Do you mean it is wrong to reset PM cap when vritio_gpu reset in current qemu code? Why?

Because PM is implementing the support from D3->d0 transition and if it

device in D3, the device needs to respond that it is in D3 to match the PCI spec.

Quoted 6 lines
Quoted 3 lines

Shouldn't all device states, including PM registers, be reset during the process of virtio-gpu reset?

If No_Soft_Reset== 0, no device context to be preserved. If No_Soft_Reset == 1, device to preserve minimal registers and other

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

things listed in pci spec.

Quoted 6 lines
Quoted 6 lines
Quoted 4 lines

So device needs to return D3 in the PowerState field. This is must.

But current behavior is a kind of soft reset, I think(!PCI_PM_CTRL_NO_SOFT_RESET). The pm cap is reset by

qemu

Quoted 29 lines
Quoted 29 lines

is

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 3 lines
Quoted 1 line

reasonable.

What you described is, you need to do No_Soft_Reset=1, so please set the

cap accordingly to achieve the restore.

Quoted 3 lines

Also in your case the if the QEMU knows that it will have to resume the

device soon.

Quoted 3 lines

Hence, it can well prepare the gpu context before resuming the vcpus. In such case, the extra register wouldn’t be necessary. Having PM control register is anyway needed to drive the device

properly.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Even as you said, the reset behavior of PM in the current QEMU code is incorrect, and even if it is modified, it also cannot fix this problem with

S3.

Quoted 12 lines
Quoted 10 lines
Quoted 7 lines

You meant D3?

Quoted 4 lines

Because there is twice device reset during resuming. First is when we trigger a resume command to qemu, qemu will reset device(qemu_system_wakeup-> qemu_devices_reset-> virtio_vga_base_reset-> virtio_gpu_gl_reset).

A device implementation that supports PM should not reset the device.

Please fix it.
Do you mean the devices_reset behavior of qemu shouldn't happen when a device has PM cap?

Right. Device reset should not happen on PM capable device that offers

Quoted 7 lines
Quoted 4 lines
Quoted 3 lines

no_soft_reset==1.
But current qemu code, no_soft_reset==0.

So please fix the qemu when you are adding the functionality of restoring

the device context on PM.
My patch didn't add the functionality of restoring the device context on PM. Is no_soft_reset must set 1 when a device has PM cap?

It the device wants to expose the ability to save and restore context, then yes, no_soft_reset = 1, as defined by the PCI spec.

Quoted 2 lines

It should also be
allowed for situations that are not equal to 1, right?

I don’t see the need of it. It would not be aligned to no_soft_reset bit already defined bit.

Quoted 3 lines

There should be devices that has PM cap but no_soft_reset is 0 because that devices can't store and restore the device context on d3->d0 transition, like current qemu code.

Right, PM cap with no_soft_reset=0, will not restore the context on d3->d0 as today.

Quoted 2 lines

So the fix should be feasible for all situations that whether the no_soft_reset is 1 or not.

I don’t follow the "fix should be feasible".
QEMU reset the device on d3->d0 transition when no_soft_reset = 0 seems fine because it follows the defined pci spec.

Quoted 2 lines

If use PM cap, not every situation can solve current problem (display resources of GPU will be destroyed).

#24 lore raw

Re: [virtio-comment] RE: [PATCH v6 1/1] content: Add new feature VIRTIO_F_PRESERVE_RESOURCES

Quoted 139 lines · Parav Pandit
Quoted 125 lines

From: Chen, Jiqian <[email protected]>
Sent: Monday, January 15, 2024 1:51 PM

Quoted 40 lines · Parav Pandit
Quoted 40 lines

From: Chen, Jiqian <[email protected]>
Sent: Monday, January 15, 2024 1:18 PM

Quoted 35 lines · Parav Pandit
Quoted 35 lines

From: Chen, Jiqian <[email protected]>
Sent: Monday, January 15, 2024 1:03 PM

Quoted 30 lines · Parav Pandit
Quoted 30 lines

From: Chen, Jiqian <[email protected]>
Sent: Friday, January 12, 2024 2:55 PM

Quoted 9 lines · Parav Pandit
Quoted 9 lines

From: Chen, Jiqian <[email protected]>
Sent: Friday, January 12, 2024 1:55 PM

Quoted 2 lines · Parav Pandit

Hi Jiqian,

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

From: Chen, Jiqian <[email protected]>
Sent: Friday, January 12, 2024 1:11 PM

Hi all,
Sorry to reply late.
I don't know if you still remember this problem, let me briefly descript

it.

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Quoted 5 lines

I am working to implement virtgpu S3 function on Xen. Currently on Xen, if we start a guest through qemu with enabling virtgpu, and then suspend and resume guest. We can find that the guest kernel comes back, but the display doesn't. It just shown a black

screen.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

That is because during suspending, guest called into qemu and qemu destroyed all display resources and reset renderer. This made the display gone after guest resumed.
So, I add a new command for virtio-gpu that when guest is suspending, it will notify qemu and set parameter(preserver_resource) to 1 and then qemu will preserve resources, and when resuming, guest will notify qemu to set parameter to 0, and then qemu will keep the normal

actions.

Quoted 34 lines
Quoted 34 lines
Quoted 34 lines
Quoted 34 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

That can

help guest's display come back.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

When I upstream above implementation, Parav and MST suggest me

to

Quoted 29 lines
Quoted 29 lines
Quoted 14 lines
Quoted 14 lines

use

Quoted 13 lines
Quoted 13 lines

the PM capability to fix this problem instead of adding a new command or state bit.
Now, I have tried the PM capability of virtio-gpu, it can't be used to solve this problem.
The reason is:
during guest suspending, it will write D3 state through PM cap, then I can save the resources of virtio-gpu on Qemu side(set preserver_resource to 1), but during the process of resuming, the state of PM cap will be cleared by qemu resetting(qemu_system_wakeup-> qemu_devices_reset-> virtio_vga_base_reset-> virtio_gpu_gl_reset), it causes that when guest reads state from PM cap, it will find the virtio-gpu has already been D0 state,

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

This behavior needs to be fixed. As the spec listed out, " This 2-bit field is

used both to determine the current power state of a Function" Do you mean it is wrong to reset PM cap when vritio_gpu reset in current qemu code? Why?

Because PM is implementing the support from D3->d0 transition and if it

device in D3, the device needs to respond that it is in D3 to match the PCI spec.

Quoted 6 lines
Quoted 3 lines

Shouldn't all device states, including PM registers, be reset during the process of virtio-gpu reset?

If No_Soft_Reset== 0, no device context to be preserved. If No_Soft_Reset == 1, device to preserve minimal registers and other

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

things listed in pci spec.

Quoted 6 lines
Quoted 6 lines
Quoted 4 lines

So device needs to return D3 in the PowerState field. This is must.

But current behavior is a kind of soft reset, I think(!PCI_PM_CTRL_NO_SOFT_RESET). The pm cap is reset by

qemu

Quoted 29 lines
Quoted 29 lines

is

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 3 lines
Quoted 1 line

reasonable.

What you described is, you need to do No_Soft_Reset=1, so please set the

cap accordingly to achieve the restore.

Quoted 3 lines

Also in your case the if the QEMU knows that it will have to resume the

device soon.

Quoted 3 lines

Hence, it can well prepare the gpu context before resuming the vcpus. In such case, the extra register wouldn’t be necessary. Having PM control register is anyway needed to drive the device

properly.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Even as you said, the reset behavior of PM in the current QEMU code is incorrect, and even if it is modified, it also cannot fix this problem with

S3.

Quoted 12 lines
Quoted 10 lines
Quoted 7 lines

You meant D3?

Quoted 4 lines

Because there is twice device reset during resuming. First is when we trigger a resume command to qemu, qemu will reset device(qemu_system_wakeup-> qemu_devices_reset-> virtio_vga_base_reset-> virtio_gpu_gl_reset).

A device implementation that supports PM should not reset the device.

Please fix it.
Do you mean the devices_reset behavior of qemu shouldn't happen when a device has PM cap?

Right. Device reset should not happen on PM capable device that offers

Quoted 7 lines
Quoted 4 lines
Quoted 3 lines

no_soft_reset==1.
But current qemu code, no_soft_reset==0.

So please fix the qemu when you are adding the functionality of restoring

the device context on PM.
My patch didn't add the functionality of restoring the device context on PM. Is no_soft_reset must set 1 when a device has PM cap?

It the device wants to expose the ability to save and restore context, then yes, no_soft_reset = 1, as defined by the PCI spec.

Quoted 2 lines

It should also be
allowed for situations that are not equal to 1, right?

I don’t see the need of it. It would not be aligned to no_soft_reset bit already defined bit.

Quoted 8 lines
Quoted 3 lines

There should be devices that has PM cap but no_soft_reset is 0 because that devices can't store and restore the device context on d3->d0 transition, like current qemu code.

Right, PM cap with no_soft_reset=0, will not restore the context on d3->d0 as today.

Quoted 2 lines

So the fix should be feasible for all situations that whether the no_soft_reset is 1 or not.

I don’t follow the "fix should be feasible".

I mean the fix that to solve the problem(virtio-gpu's display resources are destroyed during S3) should also be feasible to the situation that no_soft_reset == 0.

Quoted 1 line

QEMU reset the device on d3->d0 transition when no_soft_reset = 0 seems fine because it follows the defined pci spec.

Right.
Now that you also think the current implementation of QEMU is reasonable, the fix to this problem(display resources are destroyed during S3) should be applicable to the current QEMU code. If using PM cap, it cannot solve the problem encountered in current QEMU code.
I think you may not have had a detailed understanding of my modifications. I will resend the latest modifications on the Linux kernel and QEMU to upstream. Welcome to review.

Quoted 3 lines
Quoted 3 lines

If use PM cap, not every situation can solve current problem (display resources of GPU will be destroyed).

Signature · 2 lines
Best regards,
Jiqian Chen.
#25 lore raw

RE: [virtio-comment] RE: [PATCH v6 1/1] content: Add new feature VIRTIO_F_PRESERVE_RESOURCES

Quoted 168 lines

From: Chen, Jiqian <[email protected]>
Sent: Monday, January 15, 2024 2:40 PM

Quoted 54 lines · Parav Pandit
Quoted 54 lines

From: Chen, Jiqian <[email protected]>
Sent: Monday, January 15, 2024 1:51 PM

Quoted 49 lines · Parav Pandit
Quoted 49 lines

From: Chen, Jiqian <[email protected]>
Sent: Monday, January 15, 2024 1:18 PM

Quoted 44 lines · Parav Pandit
Quoted 44 lines

From: Chen, Jiqian <[email protected]>
Sent: Monday, January 15, 2024 1:03 PM

Quoted 39 lines · Parav Pandit
Quoted 39 lines

From: Chen, Jiqian <[email protected]>
Sent: Friday, January 12, 2024 2:55 PM

Quoted 9 lines · Parav Pandit
Quoted 9 lines

From: Chen, Jiqian <[email protected]>
Sent: Friday, January 12, 2024 1:55 PM

Quoted 2 lines · Parav Pandit

Hi Jiqian,

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

From: Chen, Jiqian <[email protected]>
Sent: Friday, January 12, 2024 1:11 PM

Hi all,
Sorry to reply late.
I don't know if you still remember this problem, let me
briefly descript

it.

Quoted 15 lines
Quoted 15 lines
Quoted 5 lines
Quoted 5 lines

I am working to implement virtgpu S3 function on Xen.
Currently on Xen, if we start a guest through qemu with
enabling virtgpu, and then suspend and resume guest. We can
find that the guest kernel comes back, but the display doesn't.
It just shown a black

screen.

Quoted 9 lines
Quoted 9 lines

That is because during suspending, guest called into qemu
and qemu destroyed all display resources and reset
renderer. This made the display gone after guest resumed.
So, I add a new command for virtio-gpu that when guest is
suspending, it will notify qemu and set
parameter(preserver_resource) to 1 and then qemu will
preserve resources, and when resuming, guest will notify
qemu to set parameter to 0, and then qemu will keep the
normal

Quoted 4 lines
Quoted 4 lines

actions.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

That can

help guest's display come back.

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

When I upstream above implementation, Parav and MST

suggest

Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

me

to

Quoted 26 lines
Quoted 26 lines
Quoted 14 lines
Quoted 14 lines

use

Quoted 13 lines
Quoted 13 lines

the PM capability to fix this problem instead of adding a
new command or state bit.
Now, I have tried the PM capability of virtio-gpu, it can't
be used to solve this problem.
The reason is:
during guest suspending, it will write D3 state through PM
cap, then I can save the resources of virtio-gpu on Qemu
side(set preserver_resource to 1), but during the process
of resuming, the state of PM cap will be cleared by qemu
resetting(qemu_system_wakeup-> qemu_devices_reset->
virtio_vga_base_reset-> virtio_gpu_gl_reset), it causes
that when guest reads state from PM cap, it will find the
virtio-gpu has already been D0 state,

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

This behavior needs to be fixed. As the spec listed out, " This 2-bit field is

used both to determine the current power state of a Function" Do you mean it is wrong to reset PM cap when vritio_gpu reset in current qemu code? Why?

Because PM is implementing the support from D3->d0 transition and if it

device in D3, the device needs to respond that it is in D3 to match the PCI spec.

Quoted 3 lines
Quoted 3 lines

Shouldn't all device states, including PM registers, be reset during the process of virtio-gpu reset?

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 3 lines

If No_Soft_Reset== 0, no device context to be preserved. If No_Soft_Reset == 1, device to preserve minimal registers and other

things listed in pci spec.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

So device needs to return D3 in the PowerState field. This is

must.

Quoted 5 lines
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

But current behavior is a kind of soft reset, I think(!PCI_PM_CTRL_NO_SOFT_RESET). The pm cap is reset by

qemu

Quoted 2 lines
Quoted 2 lines

is

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

reasonable.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 2 lines

What you described is, you need to do No_Soft_Reset=1, so please set the

cap accordingly to achieve the restore.

Quoted 3 lines

Also in your case the if the QEMU knows that it will have to resume the

device soon.

Quoted 1 line

Hence, it can well prepare the gpu context before resuming the

vcpus.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

In such case, the extra register wouldn’t be necessary. Having PM control register is anyway needed to drive the device

properly.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Even as you said, the reset behavior of PM in the current QEMU code is incorrect, and even if it is modified, it also cannot fix this problem with

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

S3.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

You meant D3?

Quoted 4 lines

Because there is twice device reset during resuming. First is when we trigger a resume command to qemu, qemu will reset device(qemu_system_wakeup-> qemu_devices_reset-> virtio_vga_base_reset-> virtio_gpu_gl_reset).

A device implementation that supports PM should not reset the

device.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines

Please fix it.
Do you mean the devices_reset behavior of qemu shouldn't happen when a device has PM cap?

Right. Device reset should not happen on PM capable device that offers

Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

no_soft_reset==1.
But current qemu code, no_soft_reset==0.

So please fix the qemu when you are adding the functionality of restoring

the device context on PM.
My patch didn't add the functionality of restoring the device context on

PM.

Quoted 3 lines
Quoted 1 line

Is no_soft_reset must set 1 when a device has PM cap?

It the device wants to expose the ability to save and restore context, then

yes, no_soft_reset = 1, as defined by the PCI spec.

Quoted 4 lines
Quoted 3 lines

It should also be
allowed for situations that are not equal to 1, right?

I don’t see the need of it. It would not be aligned to no_soft_reset bit already

defined bit.

Quoted 5 lines
Quoted 4 lines

There should be devices that has PM cap but no_soft_reset is 0 because that devices can't store and restore the device context on d3->d0 transition, like current qemu code.

Right, PM cap with no_soft_reset=0, will not restore the context on d3->d0

as today.

Quoted 5 lines
Quoted 4 lines

So the fix should be feasible for all situations that whether the no_soft_reset is
1 or not.

I don’t follow the "fix should be feasible".

I mean the fix that to solve the problem(virtio-gpu's display resources are destroyed during S3) should also be feasible to the situation that no_soft_reset == 0.

Quoted 6 lines
Quoted 1 line

QEMU reset the device on d3->d0 transition when no_soft_reset = 0 seems

fine because it follows the defined pci spec.
Right.
Now that you also think the current implementation of QEMU is reasonable, the fix to this problem(display resources are destroyed during S3) should be applicable to the current QEMU code.

Yes.

To conclude our discussion,

Display resources should be only restored when following conditions are met.
1. PCI PM cap is reported.
2. PCI PM cap has non_soft_reset=1
3. virtio guest driver do not perform reset when transport offers a restore capability using #1 and #2.

Do you agree? Yes?

Quoted 6 lines

If using PM cap, it cannot solve the problem encountered in current QEMU code.
I think you may not have had a detailed understanding of my modifications. I will resend the latest modifications on the Linux kernel and QEMU to upstream.
Welcome to review.

#26 lore raw

Re: [virtio-comment] RE: [PATCH v6 1/1] content: Add new feature VIRTIO_F_PRESERVE_RESOURCES

Quoted 176 lines · Parav Pandit
Quoted 168 lines

From: Chen, Jiqian <[email protected]>
Sent: Monday, January 15, 2024 2:40 PM

Quoted 54 lines · Parav Pandit
Quoted 54 lines

From: Chen, Jiqian <[email protected]>
Sent: Monday, January 15, 2024 1:51 PM

Quoted 49 lines · Parav Pandit
Quoted 49 lines

From: Chen, Jiqian <[email protected]>
Sent: Monday, January 15, 2024 1:18 PM

Quoted 44 lines · Parav Pandit
Quoted 44 lines

From: Chen, Jiqian <[email protected]>
Sent: Monday, January 15, 2024 1:03 PM

Quoted 39 lines · Parav Pandit
Quoted 39 lines

From: Chen, Jiqian <[email protected]>
Sent: Friday, January 12, 2024 2:55 PM

Quoted 9 lines · Parav Pandit
Quoted 9 lines

From: Chen, Jiqian <[email protected]>
Sent: Friday, January 12, 2024 1:55 PM

Quoted 2 lines · Parav Pandit

Hi Jiqian,

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

From: Chen, Jiqian <[email protected]>
Sent: Friday, January 12, 2024 1:11 PM

Hi all,
Sorry to reply late.
I don't know if you still remember this problem, let me
briefly descript

it.

Quoted 15 lines
Quoted 15 lines
Quoted 5 lines

I am working to implement virtgpu S3 function on Xen.
Currently on Xen, if we start a guest through qemu with
enabling virtgpu, and then suspend and resume guest. We can
find that the guest kernel comes back, but the display doesn't.
It just shown a black

screen.

Quoted 9 lines

That is because during suspending, guest called into qemu
and qemu destroyed all display resources and reset
renderer. This made the display gone after guest resumed.
So, I add a new command for virtio-gpu that when guest is
suspending, it will notify qemu and set
parameter(preserver_resource) to 1 and then qemu will
preserve resources, and when resuming, guest will notify
qemu to set parameter to 0, and then qemu will keep the
normal

Quoted 4 lines
Quoted 4 lines

actions.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

That can

help guest's display come back.

Quoted 1 line
Quoted 1 line
Quoted 1 line

When I upstream above implementation, Parav and MST

suggest

Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

me

to

Quoted 26 lines
Quoted 26 lines
Quoted 14 lines
Quoted 14 lines

use

Quoted 13 lines

the PM capability to fix this problem instead of adding a
new command or state bit.
Now, I have tried the PM capability of virtio-gpu, it can't
be used to solve this problem.
The reason is:
during guest suspending, it will write D3 state through PM
cap, then I can save the resources of virtio-gpu on Qemu
side(set preserver_resource to 1), but during the process
of resuming, the state of PM cap will be cleared by qemu
resetting(qemu_system_wakeup-> qemu_devices_reset->
virtio_vga_base_reset-> virtio_gpu_gl_reset), it causes
that when guest reads state from PM cap, it will find the
virtio-gpu has already been D0 state,

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

This behavior needs to be fixed. As the spec listed out, "
This 2-bit field is

used both to determine the current power state of a Function" Do you mean it is wrong to reset PM cap when vritio_gpu reset in current qemu code? Why?

Because PM is implementing the support from D3->d0 transition and if it

device in D3, the device needs to respond that it is in D3 to match the PCI spec.

Quoted 3 lines
Quoted 3 lines

Shouldn't all device states, including PM registers, be reset during the process of virtio-gpu reset?

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 3 lines

If No_Soft_Reset== 0, no device context to be preserved. If No_Soft_Reset == 1, device to preserve minimal registers and other

things listed in pci spec.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

So device needs to return D3 in the PowerState field. This is

must.

Quoted 5 lines
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

But current behavior is a kind of soft reset, I think(!PCI_PM_CTRL_NO_SOFT_RESET). The pm cap is reset by

qemu

Quoted 2 lines
Quoted 2 lines

is

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

reasonable.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 2 lines

What you described is, you need to do No_Soft_Reset=1, so please set the

cap accordingly to achieve the restore.

Quoted 3 lines

Also in your case the if the QEMU knows that it will have to resume the

device soon.

Quoted 1 line

Hence, it can well prepare the gpu context before resuming the

vcpus.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

In such case, the extra register wouldn’t be necessary. Having PM control register is anyway needed to drive the device

properly.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Even as you said, the reset behavior of PM in the current QEMU code is incorrect, and even if it is modified, it also cannot fix this problem with

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

S3.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

You meant D3?

Quoted 4 lines

Because there is twice device reset during resuming. First is when we trigger a resume command to qemu, qemu will reset device(qemu_system_wakeup-> qemu_devices_reset-> virtio_vga_base_reset-> virtio_gpu_gl_reset).

A device implementation that supports PM should not reset the

device.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines

Please fix it.
Do you mean the devices_reset behavior of qemu shouldn't happen when a device has PM cap?

Right. Device reset should not happen on PM capable device that offers

Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

no_soft_reset==1.
But current qemu code, no_soft_reset==0.

So please fix the qemu when you are adding the functionality of restoring

the device context on PM.
My patch didn't add the functionality of restoring the device context on

PM.

Quoted 3 lines
Quoted 1 line

Is no_soft_reset must set 1 when a device has PM cap?

It the device wants to expose the ability to save and restore context, then

yes, no_soft_reset = 1, as defined by the PCI spec.

Quoted 4 lines
Quoted 3 lines

It should also be
allowed for situations that are not equal to 1, right?

I don’t see the need of it. It would not be aligned to no_soft_reset bit already

defined bit.

Quoted 5 lines
Quoted 4 lines

There should be devices that has PM cap but no_soft_reset is 0 because that devices can't store and restore the device context on d3->d0 transition, like current qemu code.

Right, PM cap with no_soft_reset=0, will not restore the context on d3->d0

as today.

Quoted 5 lines
Quoted 4 lines

So the fix should be feasible for all situations that whether the no_soft_reset is
1 or not.

I don’t follow the "fix should be feasible".

I mean the fix that to solve the problem(virtio-gpu's display resources are destroyed during S3) should also be feasible to the situation that no_soft_reset == 0.

Quoted 6 lines
Quoted 1 line

QEMU reset the device on d3->d0 transition when no_soft_reset = 0 seems

fine because it follows the defined pci spec.
Right.
Now that you also think the current implementation of QEMU is reasonable, the fix to this problem(display resources are destroyed during S3) should be applicable to the current QEMU code.

Yes.

Quoted 8 lines

To conclude our discussion,

Display resources should be only restored when following conditions are met.
1. PCI PM cap is reported.
2. PCI PM cap has non_soft_reset=1
3. virtio guest driver do not perform reset when transport offers a restore capability using #1 and #2.

Do you agree? Yes?

Yes, I think this problem (display resources are destroyed during S3) can be sorted to two situations:
First is what you said above, in this situation, the devices_reset of qemu is unreasonable, if a device has PM cap and non_soft_reset=1, qemu should not do resetting. Second is without #1 or #2, the reset behavior is fine. My patch is to fix this situation, that sending a new virtio-gpu command to notify qemu to prevent destroying display resources during S3.

Quoted 7 lines
Quoted 7 lines

If using PM cap, it cannot solve the problem encountered in current QEMU code.
I think you may not have had a detailed understanding of my modifications. I will resend the latest modifications on the Linux kernel and QEMU to upstream.
Welcome to review.

Signature · 2 lines
Best regards,
Jiqian Chen.
#27 lore raw

RE: [virtio-comment] RE: [PATCH v6 1/1] content: Add new feature VIRTIO_F_PRESERVE_RESOURCES

Quoted 18 lines

From: Chen, Jiqian <[email protected]>
Sent: Monday, January 15, 2024 3:10 PM

Quoted 1 line

Display resources should be only restored when following conditions are

met.

Quoted 3 lines

1. PCI PM cap is reported.
2. PCI PM cap has non_soft_reset=1
3. virtio guest driver do not perform reset when transport offers a restore

capability using #1 and #2.

Quoted 2 lines

Do you agree? Yes?

Yes, I think this problem (display resources are destroyed during S3) can be sorted to two situations:
First is what you said above, in this situation, the devices_reset of qemu is unreasonable, if a device has PM cap and non_soft_reset=1, qemu should not do resetting.

Quoted 3 lines

Second is without #1 or #2, the reset behavior is fine. My patch is to fix this situation, that sending a new virtio-gpu command to notify qemu to prevent destroying display resources during S3.

I still have hard time following "My patch is to fix this situation...".

When #1 and #2 is not done, there is nothing to restore.
Driver should not send some new virtio specific command when #1 and #2 is not there.
Instead, if the device wants to restore the context, all #1, #2 and #3 should be done to implement the restore functionality.

In other words, if one wants to use device context restore on PM state transition it should do #1, #2 and #3. (and avoid inventing new infrastructure because PCI PM has necessary things).

#28 lore raw

Re: [virtio-comment] RE: [PATCH v6 1/1] content: Add new feature VIRTIO_F_PRESERVE_RESOURCES

Quoted 22 lines · Parav Pandit
Quoted 18 lines

From: Chen, Jiqian <[email protected]>
Sent: Monday, January 15, 2024 3:10 PM

Quoted 1 line

Display resources should be only restored when following conditions are

met.

Quoted 3 lines

1. PCI PM cap is reported.
2. PCI PM cap has non_soft_reset=1
3. virtio guest driver do not perform reset when transport offers a restore

capability using #1 and #2.

Quoted 2 lines

Do you agree? Yes?

Yes, I think this problem (display resources are destroyed during S3) can be sorted to two situations:
First is what you said above, in this situation, the devices_reset of qemu is unreasonable, if a device has PM cap and non_soft_reset=1, qemu should not do resetting.

Quoted 3 lines

Second is without #1 or #2, the reset behavior is fine. My patch is to fix this situation, that sending a new virtio-gpu command to notify qemu to prevent destroying display resources during S3.

Quoted 5 lines

I still have hard time following "My patch is to fix this situation...".

When #1 and #2 is not done, there is nothing to restore.
Driver should not send some new virtio specific command when #1 and #2 is not there.
Instead, if the device wants to restore the context, all #1, #2 and #3 should be done to implement the restore functionality.

When #1 and #2 is done. The "device reset behavior" should not happen. And then the display resources are not destroyed.
I didn’t say send command to restore context.
I mean when #1 and #2 is not done. Driver and qemu both reset devices when resuming, at that time, we need a method to prevent the display resources from destroying.
I don't mean anything else, I just feel like you may not have understood the issues I encountered during the S3 process and the implementation logic of my patch from the beginning.
In current kernel and qemu codes, when we do S3(suspend and resume) for guest, during the resuming, qemu and guest driver will reset the virtio-gpu(because #2 is not done), but once the resetting happens, the display resources will be destroyed and we can't restore, so we must add a method to prevent destroying resources at that situation. What my patch do is to add a new virtio-gpu command to notify qemu to check if the display resources should be destroyed during resetting.

Quoted 3 lines

In other words, if one wants to use device context restore on PM state transition it should do #1, #2 and #3. (and avoid inventing new infrastructure because PCI PM has necessary things).

Signature · 2 lines
Best regards,
Jiqian Chen.
#29 lore raw

RE: [virtio-comment] RE: [PATCH v6 1/1] content: Add new feature VIRTIO_F_PRESERVE_RESOURCES

Quoted 34 lines

From: Chen, Jiqian <[email protected]>
Sent: Monday, January 15, 2024 4:17 PM

Quoted 20 lines · Parav Pandit
Quoted 19 lines

From: Chen, Jiqian <[email protected]>
Sent: Monday, January 15, 2024 3:10 PM

Quoted 2 lines

Display resources should be only restored when following conditions are

met.

Quoted 4 lines

1. PCI PM cap is reported.
2. PCI PM cap has non_soft_reset=1
3. virtio guest driver do not perform reset when transport offers a restore

capability using #1 and #2.

Quoted 2 lines

Do you agree? Yes?

Yes, I think this problem (display resources are destroyed during S3) can be sorted to two situations:
First is what you said above, in this situation, the devices_reset of qemu is unreasonable, if a device has PM cap and non_soft_reset=1, qemu should not do resetting.

Quoted 8 lines
Quoted 3 lines

Second is without #1 or #2, the reset behavior is fine. My patch is to fix this situation, that sending a new virtio-gpu command to notify qemu to prevent destroying display resources during S3.

I still have hard time following "My patch is to fix this situation...".

When #1 and #2 is not done, there is nothing to restore. Driver should not send some new virtio specific command when #1 and #2 is

not there.

Quoted 8 lines
Quoted 1 line

Instead, if the device wants to restore the context, all #1, #2 and #3 should

be done to implement the restore functionality.
When #1 and #2 is done. The "device reset behavior" should not happen. And then the display resources are not destroyed.
I didn’t say send command to restore context.

I mean when #1 and #2 is not done. Driver and qemu both reset devices when resuming, at that time,

Above behavior is as per the spec guidelines. Hence it is fine.

Quoted 1 line

we need a method to prevent the display resources from destroying.

I disagree to above as it is not as per the spec guidelines. Just follow #1, #2 and #3 to not destroy the display resource destroying. No need for any check command etc.

Quoted 21 lines

I don't mean anything else, I just feel like you may not have understood the issues I encountered during the S3 process and the implementation logic of my patch from the beginning.
In current kernel and qemu codes, when we do S3(suspend and resume) for guest, during the resuming, qemu and guest driver will reset the virtio- gpu(because #2 is not done), but once the resetting happens, the display resources will be destroyed and we can't restore, so we must add a method to prevent destroying resources at that situation. What my patch do is to add a new virtio-gpu command to notify qemu to check if the display resources should be destroyed during resetting.

Quoted 2 lines

In other words, if one wants to use device context restore on PM state

transition it should do #1, #2 and #3.

Quoted 1 line

(and avoid inventing new infrastructure because PCI PM has necessary

things).

--
Best regards,
Jiqian Chen.

#30 lore raw

Re: [virtio-comment] RE: [PATCH v6 1/1] content: Add new feature VIRTIO_F_PRESERVE_RESOURCES

Quoted 40 lines · Parav Pandit
Quoted 39 lines

From: Chen, Jiqian <[email protected]>
Sent: Monday, January 15, 2024 4:17 PM

Quoted 20 lines · Parav Pandit
Quoted 19 lines

From: Chen, Jiqian <[email protected]>
Sent: Monday, January 15, 2024 3:10 PM

Quoted 2 lines

Display resources should be only restored when following conditions are

met.

Quoted 4 lines

1. PCI PM cap is reported.
2. PCI PM cap has non_soft_reset=1
3. virtio guest driver do not perform reset when transport offers a restore

capability using #1 and #2.

Quoted 2 lines

Do you agree? Yes?

Yes, I think this problem (display resources are destroyed during S3) can be sorted to two situations:
First is what you said above, in this situation, the devices_reset of qemu is unreasonable, if a device has PM cap and non_soft_reset=1, qemu should not do resetting.

Quoted 8 lines
Quoted 3 lines

Second is without #1 or #2, the reset behavior is fine. My patch is to fix this situation, that sending a new virtio-gpu command to notify qemu to prevent destroying display resources during S3.

I still have hard time following "My patch is to fix this situation...".

When #1 and #2 is not done, there is nothing to restore. Driver should not send some new virtio specific command when #1 and #2 is

not there.

Quoted 1 line

Instead, if the device wants to restore the context, all #1, #2 and #3 should

be done to implement the restore functionality.
When #1 and #2 is done. The "device reset behavior" should not happen. And then the display resources are not destroyed.
I didn’t say send command to restore context.

Quoted 7 lines
Quoted 2 lines

I mean when #1 and #2 is not done. Driver and qemu both reset devices when resuming, at that time,

Above behavior is as per the spec guidelines. Hence it is fine.

Quoted 1 line

we need a method to prevent the display resources from destroying.

I disagree to above as it is not as per the spec guidelines. Just follow #1, #2 and #3 to not destroy the display resource destroying.

I agree that follow #1, #2 and #3 will not destroy display resource.
So the question goes back: If there is no #2 and you say that the reset behavior complies with the spec guidelines, how can I make the virtio gpu work properly with display resources destroyed? What my patch do is not to prevent resetting, is to prevent destroying resources during resetting. Gerd Hoffmann has agreed to this point in my qemu patch reviewing. Even if I use PM cap, I still need to prevent destroying resources during resetting.

Quoted 23 lines

No need for any check command etc.

Quoted 21 lines

I don't mean anything else, I just feel like you may not have understood the issues I encountered during the S3 process and the implementation logic of my patch from the beginning.
In current kernel and qemu codes, when we do S3(suspend and resume) for guest, during the resuming, qemu and guest driver will reset the virtio- gpu(because #2 is not done), but once the resetting happens, the display resources will be destroyed and we can't restore, so we must add a method to prevent destroying resources at that situation. What my patch do is to add a new virtio-gpu command to notify qemu to check if the display resources should be destroyed during resetting.

Quoted 2 lines

In other words, if one wants to use device context restore on PM state

transition it should do #1, #2 and #3.

Quoted 1 line

(and avoid inventing new infrastructure because PCI PM has necessary

things).

--
Best regards,
Jiqian Chen.

Signature · 2 lines
Best regards,
Jiqian Chen.
#31 lore raw

RE: [virtio-comment] RE: [PATCH v6 1/1] content: Add new feature VIRTIO_F_PRESERVE_RESOURCES

Quoted 50 lines

From: Chen, Jiqian <[email protected]>
Sent: Monday, January 15, 2024 4:37 PM

Quoted 45 lines · Parav Pandit
Quoted 36 lines

From: Chen, Jiqian <[email protected]>
Sent: Monday, January 15, 2024 4:17 PM

Quoted 23 lines · Parav Pandit
Quoted 19 lines

From: Chen, Jiqian <[email protected]>
Sent: Monday, January 15, 2024 3:10 PM

Quoted 2 lines

Display resources should be only restored when following conditions are

met.

Quoted 3 lines

1. PCI PM cap is reported.
2. PCI PM cap has non_soft_reset=1 3. virtio guest driver do not perform reset when transport offers a restore

capability using #1 and #2.

Quoted 2 lines

Do you agree? Yes?

Yes, I think this problem (display resources are destroyed during S3) can be sorted to two situations:
First is what you said above, in this situation, the devices_reset of qemu is unreasonable, if a device has PM cap and non_soft_reset=1, qemu should not do resetting.

Quoted 3 lines

Second is without #1 or #2, the reset behavior is fine. My patch is to fix this situation, that sending a new virtio-gpu command to notify qemu to prevent destroying display resources during S3.

Quoted 5 lines

I still have hard time following "My patch is to fix this situation...".

When #1 and #2 is not done, there is nothing to restore. Driver should not send some new virtio specific command when #1 and #2 is

not there.

Quoted 2 lines

Instead, if the device wants to restore the context, all #1, #2 and #3 should

Quoted 7 lines

be done to implement the restore functionality.
When #1 and #2 is done. The "device reset behavior" should not happen. And then the display resources are not destroyed. I didn’t say send command to restore context.

I mean when #1 and #2 is not done. Driver and qemu both reset devices when resuming, at that time,

Above behavior is as per the spec guidelines. Hence it is fine.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

we need a method to prevent the display resources from destroying.

I disagree to above as it is not as per the spec guidelines. Just follow #1, #2 and #3 to not destroy the display resource destroying.

I agree that follow #1, #2 and #3 will not destroy display resource. So the question goes back: If there is no #2 and you say that the reset behavior complies with the spec guidelines, how can I make the virtio gpu work properly with display resources destroyed?

Implement #2. :)

Quoted 5 lines

What my patch do is not to prevent resetting, is to prevent destroying resources during resetting. Gerd Hoffmann has agreed to this point in my qemu patch reviewing.
Even if I use PM cap, I still need to prevent destroying resources during resetting.

Do you mean when virtio device is reset, you want to prevent?
If so, that is yet additional virtio spec hack that must be avoided as reset flow should be one. Please do #3 to avoid resetting the device.

#32 lore raw

Re: [virtio-comment] RE: [PATCH v6 1/1] content: Add new feature VIRTIO_F_PRESERVE_RESOURCES

Quoted 50 lines · Parav Pandit
Quoted 50 lines

From: Chen, Jiqian <[email protected]>
Sent: Monday, January 15, 2024 4:37 PM

Quoted 45 lines · Parav Pandit
Quoted 36 lines

From: Chen, Jiqian <[email protected]>
Sent: Monday, January 15, 2024 4:17 PM

Quoted 23 lines · Parav Pandit
Quoted 19 lines

From: Chen, Jiqian <[email protected]>
Sent: Monday, January 15, 2024 3:10 PM

Quoted 2 lines

Display resources should be only restored when following conditions are

met.

Quoted 3 lines

1. PCI PM cap is reported.
2. PCI PM cap has non_soft_reset=1 3. virtio guest driver do not perform reset when transport offers a restore

capability using #1 and #2.

Quoted 2 lines

Do you agree? Yes?

Yes, I think this problem (display resources are destroyed during S3) can be sorted to two situations:
First is what you said above, in this situation, the devices_reset of qemu is unreasonable, if a device has PM cap and non_soft_reset=1, qemu should not do resetting.

Quoted 3 lines

Second is without #1 or #2, the reset behavior is fine. My patch is to fix this situation, that sending a new virtio-gpu command to notify qemu to prevent destroying display resources during S3.

Quoted 5 lines

I still have hard time following "My patch is to fix this situation...".

When #1 and #2 is not done, there is nothing to restore. Driver should not send some new virtio specific command when #1 and #2 is

not there.

Quoted 2 lines

Instead, if the device wants to restore the context, all #1, #2 and #3 should

Quoted 7 lines

be done to implement the restore functionality.
When #1 and #2 is done. The "device reset behavior" should not happen. And then the display resources are not destroyed. I didn’t say send command to restore context.

I mean when #1 and #2 is not done. Driver and qemu both reset devices when resuming, at that time,

Above behavior is as per the spec guidelines. Hence it is fine.

Quoted 8 lines
Quoted 7 lines
Quoted 3 lines
Quoted 1 line

we need a method to prevent the display resources from destroying.

I disagree to above as it is not as per the spec guidelines. Just follow #1, #2 and #3 to not destroy the display resource destroying.

I agree that follow #1, #2 and #3 will not destroy display resource. So the question goes back: If there is no #2 and you say that the reset behavior complies with the spec guidelines, how can I make the virtio gpu work properly with display resources destroyed?

Implement #2. :)

We can't simply implement #2 if a device doesn't have #2, see Section 7.5.2.2 in PCI Express Spec, about No_Soft_Reset:
" If a VF implements the Power Management Capability, the VF's value of this field must be identical to the associated PF's value. "
What's more, a device doesn't have #2 is allowed, we should consider how to solve the two situations(No_Soft_Reset=1 and No_Soft_Reset=0), rather than simply considering implementing #2 for the device when it does not have #2.
Also in PCI Express Spec:
" Functional context is required to be maintained by Functions in the D3Hot state if the No_Soft_Reset field in the PMCSR is Set. In this case, System Software is not required to re-initialize the Function after a transition from D3Hot to D0 (the Function will be in the D0active state). If the No_Soft_Reset bit is Clear, functional context is not required to be maintained by the Function in the D3Hot state." This description corresponds to the two situations we are discussing.
First is a device has #2(No_Soft_Reset=1), the device resetting will not happen, then the display resources of virtio-gpu problem will not happen.
But in Second, a device doesn't have #2(No_Soft_Reset=0), it is fine for system to do device resetting, at this time, the display resources of virtio-gpu problem will happen, we should also consider a method to solve that problem, but not to implement #2.

Quoted 7 lines
Quoted 6 lines

What my patch do is not to prevent resetting, is to prevent destroying resources during resetting. Gerd Hoffmann has agreed to this point in my qemu patch reviewing.
Even if I use PM cap, I still need to prevent destroying resources during resetting.

Do you mean when virtio device is reset, you want to prevent?

I want to protect display resources, not to prevent the whole process of device resetting.
Also in PCI Express Spec:
"Note that a Function's software driver participates in the process of transitioning the Function from D0 to D3Hot. It contributes to the process by saving any functional state that would otherwise be lost with removal of main power, and otherwise preparing the Function for the transition to D3Hot." I let guest driver to notify qemu to protect the display resources that will be loss during S3, it is also compliant with Spec.

Quoted 2 lines

If so, that is yet additional virtio spec hack that must be avoided as reset flow should be one. Please do #3 to avoid resetting the device.

The same reason as above. According to the regulations of the spec, we should allow for the occurrence of two situations(No_Soft_Reset=1 and No_Soft_Reset=0) and provide solutions for each situation, rather than simply categorizing them into one.

Signature · 2 lines
Best regards,
Jiqian Chen.
#33 lore raw

RE: [virtio-comment] RE: [PATCH v6 1/1] content: Add new feature VIRTIO_F_PRESERVE_RESOURCES

Quoted 58 lines

From: Chen, Jiqian <[email protected]>
Sent: Tuesday, January 16, 2024 12:08 PM

Quoted 53 lines · Parav Pandit
Quoted 53 lines

From: Chen, Jiqian <[email protected]>
Sent: Monday, January 15, 2024 4:37 PM

Quoted 48 lines · Parav Pandit
Quoted 38 lines

From: Chen, Jiqian <[email protected]>
Sent: Monday, January 15, 2024 4:17 PM

Quoted 23 lines · Parav Pandit
Quoted 19 lines

From: Chen, Jiqian <[email protected]>
Sent: Monday, January 15, 2024 3:10 PM

Quoted 2 lines

Display resources should be only restored when following conditions are

met.

Quoted 3 lines

1. PCI PM cap is reported.
2. PCI PM cap has non_soft_reset=1 3. virtio guest driver do not perform reset when transport offers a restore

capability using #1 and #2.

Quoted 2 lines

Do you agree? Yes?

Yes, I think this problem (display resources are destroyed during S3) can be sorted to two situations:
First is what you said above, in this situation, the devices_reset of qemu is unreasonable, if a device has PM cap and non_soft_reset=1, qemu should not do resetting.

Quoted 3 lines

Second is without #1 or #2, the reset behavior is fine. My patch is to fix this situation, that sending a new virtio-gpu command to notify qemu to prevent destroying display resources during S3.

Quoted 6 lines

I still have hard time following "My patch is to fix this situation...".

When #1 and #2 is not done, there is nothing to restore. Driver should not send some new virtio specific command when #1 and
#2 is

not there.

Quoted 3 lines

Instead, if the device wants to restore the context, all #1, #2 and
#3 should

Quoted 7 lines

be done to implement the restore functionality.
When #1 and #2 is done. The "device reset behavior" should not happen. And then the display resources are not destroyed. I didn’t say send command to restore context.

I mean when #1 and #2 is not done. Driver and qemu both reset devices when resuming, at that time,

Above behavior is as per the spec guidelines. Hence it is fine.

Quoted 1 line

we need a method to prevent the display resources from destroying.

Quoted 8 lines
Quoted 7 lines
Quoted 6 lines
Quoted 2 lines

I disagree to above as it is not as per the spec guidelines. Just follow #1, #2 and #3 to not destroy the display resource destroying.

I agree that follow #1, #2 and #3 will not destroy display resource. So the question goes back: If there is no #2 and you say that the reset behavior complies with the spec guidelines, how can I make the virtio gpu work properly with display resources destroyed?

Implement #2. :)

We can't simply implement #2 if a device doesn't have #2,

How do you define "We" above?
Isn't we == device?

Quoted 7 lines

see Section 7.5.2.2
in PCI Express Spec, about No_Soft_Reset:
" If a VF implements the Power Management Capability, the VF's value of this field must be identical to the associated PF's value. "
What's more, a device doesn't have #2 is allowed, we should consider how to solve the two situations(No_Soft_Reset=1 and No_Soft_Reset=0), rather than simply considering implementing #2 for the device when it does not have #2.

A device implementation (sw or hw) that wants to offer maintain the function context will implement No_Soft_reset=1.

Quoted 7 lines

Also in PCI Express Spec:
" Functional context is required to be maintained by Functions in the D3Hot state if the No_Soft_Reset field in the PMCSR is Set. In this case, System Software is not required to re-initialize the Function after a transition from D3Hot to D0 (the Function will be in the D0active state). If the No_Soft_Reset bit is Clear, functional context is not required to be maintained by the Function in the D3Hot state."

Right. It is NOT required to maintain. Hence, lets not maintain.

Quoted 3 lines

This description corresponds to the two situations we are discussing. First is a device has #2(No_Soft_Reset=1), the device resetting will not happen, then the display resources of virtio-gpu problem will not happen.

Right.

Quoted 4 lines

But in Second, a device doesn't have #2(No_Soft_Reset=0), it is fine for system to do device resetting, at this time, the display resources of virtio-gpu problem will happen, we should also consider a method to solve that problem, but not to implement #2.

No, because as wrote in the spec, ", functional context is not required to be maintained". Hence no need to maintain.

Quoted 10 lines
Quoted 8 lines
Quoted 7 lines

What my patch do is not to prevent resetting, is to prevent destroying resources during resetting. Gerd Hoffmann has agreed to this point in my qemu patch reviewing.
Even if I use PM cap, I still need to prevent destroying resources during resetting.

Do you mean when virtio device is reset, you want to prevent?

I want to protect display resources, not to prevent the whole process of device resetting.

This is contradicting.
When you reset the device it will reset the functional context as well as guided by pci.

Quoted 7 lines

Also in PCI Express Spec:
"Note that a Function's software driver participates in the process of transitioning the Function from D0 to D3Hot. It contributes to the process by saving any functional state that would otherwise be lost with removal of main power, and otherwise preparing the Function for the transition to D3Hot." I let guest driver to notify qemu to protect the display resources that will be loss during S3, it is also compliant with Spec.

This is already done by the guest PCI driver using the PM control bits. Right?
Only thing needed is to fix the virtio layer to honor the PCI PM capabilities and skip resetting the device.

Quoted 9 lines
Quoted 2 lines

If so, that is yet additional virtio spec hack that must be avoided as reset flow

should be one.

Quoted 1 line

Please do #3 to avoid resetting the device.

The same reason as above. According to the regulations of the spec, we should allow for the occurrence of two situations(No_Soft_Reset=1 and No_Soft_Reset=0) and provide solutions for each situation, rather than simply categorizing them into one.

No_soft_reset=0 has no obligation to restore the functional context.

It seems to me that you are trying to maintain the function context EVEN on device reset for the motivation of not modifying the guest driver. If that is the motivation, is certainly not right to work around things that way.
I hope my interpretation is wrong. :)

#34 lore raw

Re: [virtio-comment] RE: [PATCH v6 1/1] content: Add new feature VIRTIO_F_PRESERVE_RESOURCES

Quoted 130 lines · Parav Pandit
Quoted 58 lines

From: Chen, Jiqian <[email protected]>
Sent: Tuesday, January 16, 2024 12:08 PM

Quoted 53 lines · Parav Pandit
Quoted 53 lines

From: Chen, Jiqian <[email protected]>
Sent: Monday, January 15, 2024 4:37 PM

Quoted 48 lines · Parav Pandit
Quoted 38 lines

From: Chen, Jiqian <[email protected]>
Sent: Monday, January 15, 2024 4:17 PM

Quoted 23 lines · Parav Pandit
Quoted 19 lines

From: Chen, Jiqian <[email protected]>
Sent: Monday, January 15, 2024 3:10 PM

Quoted 2 lines

Display resources should be only restored when following conditions are

met.

Quoted 3 lines

1. PCI PM cap is reported.
2. PCI PM cap has non_soft_reset=1 3. virtio guest driver do not perform reset when transport offers a restore

capability using #1 and #2.

Quoted 2 lines

Do you agree? Yes?

Yes, I think this problem (display resources are destroyed during S3) can be sorted to two situations:
First is what you said above, in this situation, the devices_reset of qemu is unreasonable, if a device has PM cap and non_soft_reset=1, qemu should not do resetting.

Quoted 3 lines

Second is without #1 or #2, the reset behavior is fine. My patch is to fix this situation, that sending a new virtio-gpu command to notify qemu to prevent destroying display resources during S3.

Quoted 6 lines

I still have hard time following "My patch is to fix this situation...".

When #1 and #2 is not done, there is nothing to restore. Driver should not send some new virtio specific command when #1 and
#2 is

not there.

Quoted 3 lines

Instead, if the device wants to restore the context, all #1, #2 and
#3 should

Quoted 7 lines

be done to implement the restore functionality.
When #1 and #2 is done. The "device reset behavior" should not happen. And then the display resources are not destroyed. I didn’t say send command to restore context.

I mean when #1 and #2 is not done. Driver and qemu both reset devices when resuming, at that time,

Above behavior is as per the spec guidelines. Hence it is fine.

Quoted 1 line

we need a method to prevent the display resources from destroying.

Quoted 8 lines
Quoted 7 lines
Quoted 6 lines
Quoted 2 lines

I disagree to above as it is not as per the spec guidelines. Just follow #1, #2 and #3 to not destroy the display resource destroying.

I agree that follow #1, #2 and #3 will not destroy display resource. So the question goes back: If there is no #2 and you say that the reset behavior complies with the spec guidelines, how can I make the virtio gpu work properly with display resources destroyed?

Implement #2. :)

We can't simply implement #2 if a device doesn't have #2,

How do you define "We" above?
Isn't we == device?

Quoted 7 lines

see Section 7.5.2.2
in PCI Express Spec, about No_Soft_Reset:
" If a VF implements the Power Management Capability, the VF's value of this field must be identical to the associated PF's value. "
What's more, a device doesn't have #2 is allowed, we should consider how to solve the two situations(No_Soft_Reset=1 and No_Soft_Reset=0), rather than simply considering implementing #2 for the device when it does not have #2.

A device implementation (sw or hw) that wants to offer maintain the function context will implement No_Soft_reset=1.

Quoted 7 lines

Also in PCI Express Spec:
" Functional context is required to be maintained by Functions in the D3Hot state if the No_Soft_Reset field in the PMCSR is Set. In this case, System Software is not required to re-initialize the Function after a transition from D3Hot to D0 (the Function will be in the D0active state). If the No_Soft_Reset bit is Clear, functional context is not required to be maintained by the Function in the D3Hot state."

Right. It is NOT required to maintain. Hence, lets not maintain.

Quoted 3 lines

This description corresponds to the two situations we are discussing. First is a device has #2(No_Soft_Reset=1), the device resetting will not happen, then the display resources of virtio-gpu problem will not happen.

Right.

Quoted 4 lines

But in Second, a device doesn't have #2(No_Soft_Reset=0), it is fine for system to do device resetting, at this time, the display resources of virtio-gpu problem will happen, we should also consider a method to solve that problem, but not to implement #2.

No, because as wrote in the spec, ", functional context is not required to be maintained". Hence no need to maintain.

Quoted 10 lines
Quoted 8 lines
Quoted 7 lines

What my patch do is not to prevent resetting, is to prevent destroying resources during resetting. Gerd Hoffmann has agreed to this point in my qemu patch reviewing.
Even if I use PM cap, I still need to prevent destroying resources during resetting.

Do you mean when virtio device is reset, you want to prevent?

I want to protect display resources, not to prevent the whole process of device resetting.

This is contradicting.
When you reset the device it will reset the functional context as well as guided by pci.

Quoted 7 lines

Also in PCI Express Spec:
"Note that a Function's software driver participates in the process of transitioning the Function from D0 to D3Hot. It contributes to the process by saving any functional state that would otherwise be lost with removal of main power, and otherwise preparing the Function for the transition to D3Hot." I let guest driver to notify qemu to protect the display resources that will be loss during S3, it is also compliant with Spec.

This is already done by the guest PCI driver using the PM control bits. Right?
Only thing needed is to fix the virtio layer to honor the PCI PM capabilities and skip resetting the device.

Quoted 9 lines
Quoted 2 lines

If so, that is yet additional virtio spec hack that must be avoided as reset flow

should be one.

Quoted 1 line

Please do #3 to avoid resetting the device.

The same reason as above. According to the regulations of the spec, we should allow for the occurrence of two situations(No_Soft_Reset=1 and No_Soft_Reset=0) and provide solutions for each situation, rather than simply categorizing them into one.

Quoted 5 lines

No_soft_reset=0 has no obligation to restore the functional context.

It seems to me that you are trying to maintain the function context EVEN on device reset for the motivation of not modifying the guest driver. If that is the motivation, is certainly not right to work around things that way.
I hope my interpretation is wrong. :)

You are wrong, I am not for the motivation of not modifying the guest driver. Because guest driver doesn't have enough information to recreate all the display resources, this has been discussed and agreed upon in my qemu patch review.
I just want to ask you if a device has no #2 (No_Soft_Reset=0), how do you solve the display resources of virtio-gpu destroyed problem? (Not to implement #2, because this situation exists, is reasonable, and complies with the Spec. Shouldn't we also consider how to modify code to make the virtio-gpu work properly in this situation? You can't say to directly implement #2 to eliminate the existence of this situation, can you?)

Signature · 2 lines
Best regards,
Jiqian Chen.
#35 lore raw

RE: [virtio-comment] RE: [PATCH v6 1/1] content: Add new feature VIRTIO_F_PRESERVE_RESOURCES

Quoted 147 lines

From: Chen, Jiqian <[email protected]>
Sent: Tuesday, January 16, 2024 1:51 PM

Quoted 35 lines · Parav Pandit
Quoted 35 lines

From: Chen, Jiqian <[email protected]>
Sent: Tuesday, January 16, 2024 12:08 PM

Quoted 30 lines · Parav Pandit
Quoted 30 lines

From: Chen, Jiqian <[email protected]>
Sent: Monday, January 15, 2024 4:37 PM

Quoted 25 lines · Parav Pandit
Quoted 25 lines

From: Chen, Jiqian <[email protected]>
Sent: Monday, January 15, 2024 4:17 PM

Quoted 20 lines · Parav Pandit
Quoted 19 lines

From: Chen, Jiqian <[email protected]>
Sent: Monday, January 15, 2024 3:10 PM

Quoted 2 lines

Display resources should be only restored when following conditions are

met.

Quoted 3 lines

1. PCI PM cap is reported.
2. PCI PM cap has non_soft_reset=1 3. virtio guest driver do not perform reset when transport offers a restore

capability using #1 and #2.

Quoted 2 lines

Do you agree? Yes?

Yes, I think this problem (display resources are destroyed during
S3) can be sorted to two situations:
First is what you said above, in this situation, the devices_reset of qemu is unreasonable, if a device has PM cap and non_soft_reset=1, qemu should not do resetting.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Second is without #1 or #2, the reset behavior is fine. My patch is to fix this situation, that sending a new virtio-gpu command to notify qemu to prevent destroying display resources

during S3.

Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
Quoted 11 lines
Quoted 7 lines

I still have hard time following "My patch is to fix this situation...".

When #1 and #2 is not done, there is nothing to restore. Driver should not send some new virtio specific command when #1 and
#2 is

not there.

Quoted 3 lines

Instead, if the device wants to restore the context, all #1, #2 and
#3 should

Quoted 7 lines

be done to implement the restore functionality.
When #1 and #2 is done. The "device reset behavior" should not happen. And then the display resources are not destroyed. I didn’t say send command to restore context.

I mean when #1 and #2 is not done. Driver and qemu both reset devices when resuming, at that time,

Above behavior is as per the spec guidelines. Hence it is fine.

Quoted 1 line

we need a method to prevent the display resources from destroying.

I disagree to above as it is not as per the spec guidelines. Just follow #1, #2 and #3 to not destroy the display resource destroying.

Quoted 16 lines
Quoted 6 lines
Quoted 5 lines
Quoted 4 lines

I agree that follow #1, #2 and #3 will not destroy display resource. So the question goes back: If there is no #2 and you say that the reset behavior complies with the spec guidelines, how can I make the virtio gpu work properly with display resources destroyed?

Implement #2. :)

We can't simply implement #2 if a device doesn't have #2,

How do you define "We" above?
Isn't we == device?

Quoted 7 lines

see Section 7.5.2.2
in PCI Express Spec, about No_Soft_Reset:
" If a VF implements the Power Management Capability, the VF's value of this field must be identical to the associated PF's value. " What's more, a device doesn't have #2 is allowed, we should consider how to solve the two situations(No_Soft_Reset=1 and No_Soft_Reset=0), rather than simply considering implementing #2 for the device when it does

not have #2.

Quoted 1 line

A device implementation (sw or hw) that wants to offer maintain the

function context will implement No_Soft_reset=1.

Quoted 8 lines
Quoted 8 lines

Also in PCI Express Spec:
" Functional context is required to be maintained by Functions in the D3Hot state if the No_Soft_Reset field in the PMCSR is Set. In this case, System Software is not required to re-initialize the Function after a transition from D3Hot to D0 (the Function will be in the D0active state). If the No_Soft_Reset bit is Clear, functional context is not required to be maintained by the Function in the D3Hot

state."

Quoted 5 lines

Right. It is NOT required to maintain. Hence, lets not maintain.

Quoted 3 lines

This description corresponds to the two situations we are discussing. First is a device has #2(No_Soft_Reset=1), the device resetting will not happen, then the display resources of virtio-gpu problem will not

happen.

Quoted 7 lines

Right.

Quoted 4 lines

But in Second, a device doesn't have #2(No_Soft_Reset=0), it is fine for system to do device resetting, at this time, the display resources of virtio-gpu problem will happen, we should also consider a method to solve that problem, but not to implement #2.

No, because as wrote in the spec, ", functional context is not required to be

maintained". Hence no need to maintain.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

What my patch do is not to prevent resetting, is to prevent destroying resources during resetting. Gerd Hoffmann has agreed to this point in my qemu patch reviewing.
Even if I use PM cap, I still need to prevent destroying resources during resetting.

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Do you mean when virtio device is reset, you want to prevent?

I want to protect display resources, not to prevent the whole process of device resetting.

This is contradicting.
When you reset the device it will reset the functional context as well as

guided by pci.

Quoted 6 lines
Quoted 6 lines

Also in PCI Express Spec:
"Note that a Function's software driver participates in the process of transitioning the Function from D0 to D3Hot. It contributes to the process by saving any functional state that would otherwise be lost with removal of main power, and otherwise preparing the Function for the

transition to D3Hot."

Quoted 4 lines
Quoted 2 lines

I let guest driver to notify qemu to protect the display resources that will be loss during S3, it is also compliant with Spec.

This is already done by the guest PCI driver using the PM control bits. Right? Only thing needed is to fix the virtio layer to honor the PCI PM capabilities

and skip resetting the device.

Quoted 12 lines
Quoted 12 lines
Quoted 4 lines

If so, that is yet additional virtio spec hack that must be avoided as reset flow

should be one.

Quoted 1 line

Please do #3 to avoid resetting the device.

The same reason as above. According to the regulations of the spec, we should allow for the occurrence of two situations(No_Soft_Reset=1 and
No_Soft_Reset=0) and provide solutions for each situation, rather than simply categorizing them into one.

Quoted 8 lines
Quoted 3 lines

No_soft_reset=0 has no obligation to restore the functional context.

It seems to me that you are trying to maintain the function context EVEN on

device reset for the motivation of not modifying the guest driver.

Quoted 1 line

If that is the motivation, is certainly not right to work around things that

way.

Quoted 1 line

I hope my interpretation is wrong. :)

You are wrong, I am not for the motivation of not modifying the guest driver.

Ok. good.

Quoted 3 lines

Because guest driver doesn't have enough information to recreate all the display resources, this has been discussed and agreed upon in my qemu patch review.

Ok. I am also in favor of restoring the resources on d3->d0. We are aligned for #1 and #3.

Quoted 2 lines

I just want to ask you if a device has no #2 (No_Soft_Reset=0), how do you solve the display resources of virtio-gpu destroyed problem?

By implementing #2.

(Not to> implement #2, because this situation exists, Which situation exists? Device implementation is missing #2? If so, lets improve the device implementation to do #2.

is reasonable, and complies with

Quoted 3 lines

the Spec. Shouldn't we also consider how to modify code to make the virtio- gpu work properly in this situation? You can't say to directly implement #2 to eliminate the existence of this situation, can you?)

I didn’t follow, what is the problem in implementing #2?

#36 lore raw

[virtio-comment] Re: [PATCH v6 1/1] content: Add new feature VIRTIO_F_PRESERVE_RESOURCES

In reply to Chen, Jiqian
Quoted 14 lines · Jiqian

Hi all,
Sorry to reply late.
I don't know if you still remember this problem, let me briefly descript it.
I am working to implement virtgpu S3 function on Xen.
Currently on Xen, if we start a guest through qemu with enabling virtgpu, and then suspend and resume guest. We can find that the guest kernel comes back, but the display doesn't. It just shown a black screen.
That is because during suspending, guest called into qemu and qemu destroyed all display resources and reset renderer. This made the display gone after guest resumed.
So, I add a new command for virtio-gpu that when guest is suspending, it will notify qemu and set parameter(preserver_resource) to 1 and then qemu will preserve resources, and when resuming, guest will notify qemu to set parameter to 0, and then qemu will keep the normal actions. That can help guest's display come back. When I upstream above implementation, Parav and MST suggest me to use the PM capability to fix this problem instead of adding a new command or state bit.
Now, I have tried the PM capability of virtio-gpu, it can't be used to solve this problem.
The reason is:
during guest suspending, it will write D3 state through PM cap, then I can save the resources of virtio-gpu on Qemu side(set preserver_resource to 1),
but during the process of resuming, the state of PM cap will be cleared by qemu resetting(qemu_system_wakeup-> qemu_devices_reset-> virtio_vga_base_reset-> virtio_gpu_gl_reset),
it causes that when guest reads state from PM cap, it will find the virtio-gpu has already been D0 state, so guest will not write D0 through PM cap, so I can't know when to restore the resources(set preserver_resource to 0).

Looks like a bug to be fixed?

Quoted 2 lines

Do you have any other suggestions?
Or can I just fallback to the version that add a new command(VIRTIO_GPU_CMD_PRESERVE_RESOURCE) in virtio-gpu? I think that way is more reasonable and feasible for virtio-gpu to protect display resources during S3. As for other devices, if necessary, they can also refer to the implementation of the virtio-gpu to add new commands to prevent resource loss during S3.

Note that there's recently a fix for no_soft_reset, a well behaved device should not suffer from this issue anymore. If I understand this correctly, there's no need for any extension for the spec as well.:

https://lore.kernel.org/lkml/CACGkMEs_MajTFxGVcK5R8oqQzTxuL4Pm=uUnOonDczWzqaucsw@mail.gmail.com/T/

Thanks

Quoted 173 lines · Jiqian
Quoted 170 lines

Hi Michael S. Tsirkin and Parav Pandit,
Thank you for your detailed explanation. I will try to use PM cap to fix this issue.

Quoted 165 lines · Michael S. Tsirkin
Quoted 34 lines · Jiqian
Quoted 32 lines · Parav Pandit
Quoted 32 lines

From: Chen, Jiqian <[email protected]>
Sent: Tuesday, October 24, 2023 5:44 PM

Quoted 14 lines · Parav Pandit
Quoted 14 lines

From: Chen, Jiqian <[email protected]>
Sent: Tuesday, October 24, 2023 4:06 PM

Quoted 9 lines · Parav Pandit
Quoted 9 lines

From: Chen, Jiqian <[email protected]>
Sent: Monday, October 23, 2023 4:09 PM

Quoted 3 lines

I think this can be done without introducing the new register. Can you please check if the PM register itself can serve the purpose instead

of new virtio level register?
Do you mean the system PM register?

Quoted 7 lines
Quoted 6 lines
Quoted 1 line

No, the device's PM register at transport level.

I tried to find this register(pci level or virtio pci level or virtio driver level), but I didn't find it in Linux kernel or Qemu codes. May I know which register you are referring to specifically? Or which PM state bit you mentioned below?

PCI spec's PCI Power Management Capability Structure in section 7.5.2.

Yes, what you point to is PM capability for PCIe device.
But the problem is still that in Qemu code, it will check the condition(pci_bus_is_express or pci_is_express) of all virtio-pci devices in function virtio_pci_realize(), if the virtio devices aren't a PCIe device, it will not add PM capability for them.

Quoted 5 lines
Quoted 2 lines

PCI PM capability is must for PCIe devices. So may be QEMU code has put it only under is_pcie check.
But it can be done outside of that check as well because this capability exists on PCI too for long time and it is backward compatible.

Do you suggest me to implement PM capability for virtio devices in Qemu firstly, and then to try if the PM capability can work for this scenario?

virtio devices in qemu already have a PM capability.

Quoted 1 line

If so, we will complicate a simple problem. Because there are no other needs to add PM capability for virtio devices for now, if we add it just for preserving resources, it seems unnecessary and unreasonable. And we are not sure if there are other scenarios that are not during the process of PM state changing also need to preserve resources, if have, then the PM register can't cover, but preserve_resources register can.

One of the selling points of virtio is precisely reusing existing platform capabilities as opposed to coming up with our own. See abstract.tex

Quoted 1 line

Can I add some notes like "If PM capability is implemented for virtio devices, it may cover this scenario, and if there are no other scenarios that PM can't cover, then we can remove this register " in commit message or spec description and let us continue to add preserve_resources register?

We can't remove registers.

Quoted 109 lines
Quoted 91 lines
Quoted 4 lines

And another problem is how about the MMIO transport devices? Since preserve resources is need for all transport type devices.

MMIO lacks such rich PM definitions. If in future MMIO wants to support, it will be extended to match to other transports like PCI.

Quoted 22 lines
Quoted 9 lines
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

I think it is unreasonable to let virtio- device listen the PM state of Guest system.

Guest driver performs any work on the guest systems PM callback events in

the virtio driver.
I didn't find any PM state callback in the virtio driver.

There are virtio_suspend and virtio_resume in case of Linux.

I think what you said virtio_suspend/resume is freeze/restore callback from "struct virtio_driver" or suspend/resume callback from "static const struct dev_pm_ops virtio_pci_pm_ops".
And yes, I agree, if virtio devices have PM capability, maybe we can set PM state in those callback functions.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines

It's more suitable that each device gets notifications from driver, and then do preserving resources operation.

I agree that each device gets the notification from driver. The question is, should it be virtio driver, or existing pci driver which

Quoted 9 lines
Quoted 3 lines
Quoted 3 lines

transitions the state from d0->d3 and d3->d0 is enough.
It seems there isn't existing pci driver to transitions d0 or d3 state. Could you please tell me which one it is specifically? I am very willing to

give a try.

Quoted 2 lines
Quoted 1 line

Virtio-pci modern driver of Linux should be able to.

Yes, I know, it is the VIRTIO_PCI_FLAG_INIT_PM_BIT. But still the two problems I said above.

Both can be resolved without switching to pcie.

Quoted 52 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

Can you please check that?

Quoted 3 lines
Quoted 3 lines

transport-pci.tex \subsubsection{Common configuration

Quoted 3 lines
transport-pci.tex +0 -0
@@ -325,6 +325,7 @@ \subsubsection{Common configuration

structure

Quoted 45 lines
Quoted 45 lines
Quoted 23 lines
Quoted 15 lines
Quoted 7 lines
Quoted 5 lines

layout}\label{sec:Virtio Transport
/* About the administration virtqueue. */
le16 admin_queue_index; /* read-only for driver */
le16 admin_queue_num; /* read-only for driver */
+ le16 preserve_resources; /* read-write */

Preserving these resources in the device implementation takes finite amount

of time.

Quoted 2 lines

Possibly more than 40nsec (time of PCIe write TLP). Hence this register must be a polling register to indicate that

preservation_done.

Quoted 2 lines

This will tell the guest when the preservation is done, and when restoration is

done, so that it can resume upper layers.

Quoted 1 line
Quoted 8 lines
Quoted 2 lines

Please refer to queue_reset definition to learn more about such register

definition.
Thanks, I will refer to "queue_reset". So, I need three values, driver write 1 to let device do preserving resources, driver write 2 to let device do restoring resources, device write 0 to tell driver that preserving or restoring done, am I right?

Quoted 5 lines

Right.

And if the existing pcie pm state bits can do, we can leverage that. If it cannot be used, lets add that reasoning in the commit log to describe this

register.

Quoted 9 lines
Quoted 9 lines
Quoted 4 lines

Lets please make sure that PCIe PM level registers are sufficient/not-sufficient

to decide the addition of this register.
But if the device is not a PCIe device, it doesn't have PM capability, then this will not work. Actually in my local environment, pci_is_express() return false in Qemu, they are not PCIe

device.

Quoted 3 lines

It is reasonable to ask to plug in as PCIe device in 2023 to get new functionality that too you mentioned a gpu device. 😊 Which does not have very long history of any backward compatibility.

Do you suggest me to add PM capability for virtio-gpu or change virtio-gpu to a PCIe device?

Quoted 14 lines
Quoted 6 lines
Quoted 1 line

PCI Power Management Capability Structure does not seem to be limited to

PCIe.
I am not sure, but in current Qemu code, I can see the check "pci_is_express" for all virtio-pci devices. If we want to add PM capability for virtio-pci devices, we need to change them to PCIe device I think.

That is one option.
Second option to extend PCI PM cap for non pci device because it is supported.

Quoted 5 lines
Quoted 1 line

--
Best regards,
Jiqian Chen.

--
Best regards,
Jiqian Chen.

Quoted 3 lines

--
Best regards,
Jiqian Chen.

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]

#37 lore raw

[virtio-comment] Re: [PATCH v6 1/1] content: Add new feature VIRTIO_F_PRESERVE_RESOURCES

Quoted 16 lines · Jason Wang
Quoted 14 lines · Jiqian

Hi all,
Sorry to reply late.
I don't know if you still remember this problem, let me briefly descript it.
I am working to implement virtgpu S3 function on Xen.
Currently on Xen, if we start a guest through qemu with enabling virtgpu, and then suspend and resume guest. We can find that the guest kernel comes back, but the display doesn't. It just shown a black screen.
That is because during suspending, guest called into qemu and qemu destroyed all display resources and reset renderer. This made the display gone after guest resumed.
So, I add a new command for virtio-gpu that when guest is suspending, it will notify qemu and set parameter(preserver_resource) to 1 and then qemu will preserve resources, and when resuming, guest will notify qemu to set parameter to 0, and then qemu will keep the normal actions. That can help guest's display come back. When I upstream above implementation, Parav and MST suggest me to use the PM capability to fix this problem instead of adding a new command or state bit.
Now, I have tried the PM capability of virtio-gpu, it can't be used to solve this problem.
The reason is:
during guest suspending, it will write D3 state through PM cap, then I can save the resources of virtio-gpu on Qemu side(set preserver_resource to 1),
but during the process of resuming, the state of PM cap will be cleared by qemu resetting(qemu_system_wakeup-> qemu_devices_reset-> virtio_vga_base_reset-> virtio_gpu_gl_reset),
it causes that when guest reads state from PM cap, it will find the virtio-gpu has already been D0 state, so guest will not write D0 through PM cap, so I can't know when to restore the resources(set preserver_resource to 0).

Quoted 1 line

Looks like a bug to be fixed?

Do you think the devices_reset behavior of qemu shouldn't happen? Or just the state of PM cap shouldn't be cleared?

Quoted 7 lines
Quoted 3 lines

Do you have any other suggestions?
Or can I just fallback to the version that add a new command(VIRTIO_GPU_CMD_PRESERVE_RESOURCE) in virtio-gpu? I think that way is more reasonable and feasible for virtio-gpu to protect display resources during S3. As for other devices, if necessary, they can also refer to the implementation of the virtio-gpu to add new commands to prevent resource loss during S3.

Note that there's recently a fix for no_soft_reset, a well behaved device should not suffer from this issue anymore. If I understand this correctly, there's no need for any extension for the spec as well.:

But in current qemu codes, the bit PCI_PM_CTRL_NO_SOFT_RESET of virtio-pci devices isn't set, is it a bug? Even with the fix you mentioned, the resetting can still happen because of no_soft_reset==0.

Quoted 5 lines

https://lore.kernel.org/lkml/CACGkMEs_MajTFxGVcK5R8oqQzTxuL4Pm=uUnOonDczWzqaucsw@mail.gmail.com/T/

Thanks

Best Regards,
Jiqian Chen.