virtio-comment

 View Only
Expand all | Collapse all

[PATCH v4 0/1] Define a low power mode for devices

  • 1.  [PATCH v4 0/1] Define a low power mode for devices

    Posted 02-16-2024 08:25
    The Linux patch [1] added support for suspending virtio devices using
    native PCI power management. However, Linux does PCI power management
    during the noirq phase of suspend and resume. Without a mechanism to
    suspend/resume virtio devices when the driver is suspended/resumed in
    the early phase of suspend/late phase of resume, there is a window where
    interrupts can be lost.

    [1] 20231208070754.3132339-1-stevensd@chromium.org/">https://lore.kernel.org/lkml/20231208070754.3132339-1-stevensd@chromium.org/

    v3 -> v4:
    - Define virtio-pci specific power management that can be used in
    conjunction with PCI power management.
    v2 -> v3:
    - Use different words for some concepts to avoid conflicts with other
    parts of the spec.
    - Rewrite various sentences to improve clarity.
    v1 -> v2:
    - Define virtio-pci support on top of PCI power management.
    - Add more conformance requirements.

    David Stevens (1):
    Add suspend support for virtio PCI devices

    transport-pci.tex | 51 +++++++++++++++++++++++++++++++++++++++++++++++
    1 file changed, 51 insertions(+)

    --
    2.44.0.rc0.258.g7320e95886-goog




  • 2.  [PATCH v4 1/1] Add suspend support for virtio PCI devices

    Posted 02-16-2024 08:25
    Add a virtio power management PCI capability to allow drivers to suspend
    virtio PCI devices. This allows drivers to suspend devices at the virtio
    level before suspending them at the PCI transport layer. This allows
    drivers to do a two phase suspend, which prevents notifications from
    being ignored or lost if interrupts are reconfigured at the PCI
    transport layer immediately before or after the device is put into the
    PCI PM D3 low power state.
    ---
    transport-pci.tex | 51 +++++++++++++++++++++++++++++++++++++++++++++++
    1 file changed, 51 insertions(+)

    diff --git a/transport-pci.tex b/transport-pci.tex
    index a5c6719ea871..ce77708a9b69 100644
    --- a/transport-pci.tex
    +++ b/transport-pci.tex
    @@ -188,6 +188,8 @@ \subsection{Virtio Structure PCI Capabilities}\label{sec:Virtio Transport Option
    #define VIRTIO_PCI_CAP_SHARED_MEMORY_CFG 8
    /* Vendor-specific data */
    #define VIRTIO_PCI_CAP_VENDOR_CFG 9
    +/* Power management configuration */
    +#define VIRTIO_PCI_CAP_PM_CFG 10
    \end{lstlisting}

    Any other value is reserved for future use.
    @@ -804,6 +806,55 @@ \subsubsection{PCI configuration access capability}\label{sec:Virtio Transport O
    specified by some other Virtio Structure PCI Capability
    of type other than \field{VIRTIO_PCI_CAP_PCI_CFG}.

    +\subsubsection{Power management capability}\label{sec:Virtio Transport Options / Virtio Over PCI Bus / PCI Device Layout / Power management capability}
    +
    +The VIRTIO_PCI_CAP_PM_CFG capability refers to a single byte. The
    +driver can write to the byte to set the power state of the device,
    +and it can read from the byte to get the current power state of the
    +device.
    +
    +The valid power states are:
    +
    +\begin{lstlisting}
    +/* Device is operating normally */
    +#define VIRTIO_PM_STATE_ACTIVE 0
    +/* Device operation is suspended */
    +#define VIRTIO_PM_STATE_SUSPENDED 1
    +\end{lstlisting}
    +
    +The device power state has no effect when \field{device status} does
    +not have the DRIVER_OK bit set or does have the DEVICE_NEEDS_RESET bit
    +set.
    +
    +\devicenormative{\paragraph}{Power management capability}{Virtio Transport Options / Virtio Over PCI Bus / PCI Device Layout / Power management capability}
    +
    +A device MUST maintain its state while suspended such that all driver
    +visible state after resuming exactly matches driver visible state
    +before suspending.
    +
    +A device MUST NOT send notifications while suspended.
    +
    +A device MAY operate on any buffers in its virtqueue while suspended.
    +
    +A device MUST set its power state to VIRTIO_PM_STATE_ACTIVE on reset.
    +
    +A device SHOULD take steps to minimize its resource consumption while
    +suspended, although what this involves is specific to the particular
    +device implementation.
    +
    +\drivernormative{\paragraph}{Power management capability}{Virtio Transport Options / Virtio Over PCI Bus / PCI Device Layout / Power management capability}
    +
    +A driver MUST NOT access a suspended device's BARs corresponding to
    +any virtio structures, except for the power management byte.
    +
    +A driver MAY suspend a device that has buffers in one of its
    +virtqueues, but it MUST NOT modify any such buffers while the device
    +is suspended.
    +
    +A driver MUST read from the power management byte after writing to the
    +byte to verify that the device successfully entered the target power
    +state.
    +
    \subsubsection{Legacy Interfaces: A Note on PCI Device Layout}\label{sec:Virtio Transport Options / Virtio Over PCI Bus / PCI Device Layout / Legacy Interfaces: A Note on PCI Device Layout}

    Transitional devices MUST present part of configuration
    --
    2.44.0.rc0.258.g7320e95886-goog




  • 3.  Re: [PATCH v4 1/1] Add suspend support for virtio PCI devices

    Posted 02-16-2024 08:56
    On Fri, Feb 16, 2024 at 05:24:32PM +0900, David Stevens wrote:
    > Add a virtio power management PCI capability to allow drivers to suspend
    > virtio PCI devices. This allows drivers to suspend devices at the virtio
    > level before suspending them at the PCI transport layer. This allows
    > drivers to do a two phase suspend, which prevents notifications from
    > being ignored or lost if interrupts are reconfigured at the PCI
    > transport layer immediately before or after the device is put into the
    > PCI PM D3 low power state.
    > ---
    > transport-pci.tex | 51 +++++++++++++++++++++++++++++++++++++++++++++++
    > 1 file changed, 51 insertions(+)
    >
    > diff --git a/transport-pci.tex b/transport-pci.tex
    > index a5c6719ea871..ce77708a9b69 100644
    > --- a/transport-pci.tex
    > +++ b/transport-pci.tex
    > @@ -188,6 +188,8 @@ \subsection{Virtio Structure PCI Capabilities}\label{sec:Virtio Transport Option
    > #define VIRTIO_PCI_CAP_SHARED_MEMORY_CFG 8
    > /* Vendor-specific data */
    > #define VIRTIO_PCI_CAP_VENDOR_CFG 9
    > +/* Power management configuration */
    > +#define VIRTIO_PCI_CAP_PM_CFG 10
    > \end{lstlisting}
    >
    > Any other value is reserved for future use.
    > @@ -804,6 +806,55 @@ \subsubsection{PCI configuration access capability}\label{sec:Virtio Transport O
    > specified by some other Virtio Structure PCI Capability
    > of type other than \field{VIRTIO_PCI_CAP_PCI_CFG}.
    >
    > +\subsubsection{Power management capability}\label{sec:Virtio Transport Options / Virtio Over PCI Bus / PCI Device Layout / Power management capability}
    > +
    > +The VIRTIO_PCI_CAP_PM_CFG capability refers to a single byte. The
    > +driver can write to the byte to set the power state of the device,
    > +and it can read from the byte to get the current power state of the
    > +device.
    > +
    > +The valid power states are:
    > +
    > +\begin{lstlisting}
    > +/* Device is operating normally */
    > +#define VIRTIO_PM_STATE_ACTIVE 0
    > +/* Device operation is suspended */
    > +#define VIRTIO_PM_STATE_SUSPENDED 1
    > +\end{lstlisting}
    > +
    > +The device power state has no effect when \field{device status} does
    > +not have the DRIVER_OK bit set or does have the DEVICE_NEEDS_RESET bit
    > +set.


    Given this is only after DRIVER_OK, wouldn't a feature bit + status bit
    make more sense? This will make it transport-independent and simplify
    discovery.

    > +\devicenormative{\paragraph}{Power management capability}{Virtio Transport Options / Virtio Over PCI Bus / PCI Device Layout / Power management capability}
    > +
    > +A device MUST maintain its state while suspended such that all driver
    > +visible state after resuming exactly matches driver visible state
    > +before suspending.
    > +
    > +A device MUST NOT send notifications while suspended.
    > +
    > +A device MAY operate on any buffers in its virtqueue while suspended.

    How is this reconsiled with state matching exactly? buffers are
    driver-visible ...

    > +A device MUST set its power state to VIRTIO_PM_STATE_ACTIVE on reset.
    > +
    > +A device SHOULD take steps to minimize its resource consumption while
    > +suspended, although what this involves is specific to the particular
    > +device implementation.
    > +
    > +\drivernormative{\paragraph}{Power management capability}{Virtio Transport Options / Virtio Over PCI Bus / PCI Device Layout / Power management capability}
    > +
    > +A driver MUST NOT access a suspended device's BARs corresponding to
    > +any virtio structures, except for the power management byte.
    > +
    > +A driver MAY suspend a device that has buffers in one of its
    > +virtqueues, but it MUST NOT modify any such buffers while the device
    > +is suspended.
    > +
    > +A driver MUST read from the power management byte after writing to the
    > +byte to verify that the device successfully entered the target power
    > +state.

    Verify how? By checking the value returned? And what should it do with the value
    does not match?


    > +
    > \subsubsection{Legacy Interfaces: A Note on PCI Device Layout}\label{sec:Virtio Transport Options / Virtio Over PCI Bus / PCI Device Layout / Legacy Interfaces: A Note on PCI Device Layout}
    >
    > Transitional devices MUST present part of configuration
    > --
    > 2.44.0.rc0.258.g7320e95886-goog




  • 4.  Re: [virtio-dev] Re: [PATCH v4 1/1] Add suspend support for virtio PCI devices

    Posted 02-18-2024 10:59


    On 2/16/2024 4:56 PM, Michael S. Tsirkin wrote:
    > On Fri, Feb 16, 2024 at 05:24:32PM +0900, David Stevens wrote:
    >> Add a virtio power management PCI capability to allow drivers to suspend
    >> virtio PCI devices. This allows drivers to suspend devices at the virtio
    >> level before suspending them at the PCI transport layer. This allows
    >> drivers to do a two phase suspend, which prevents notifications from
    >> being ignored or lost if interrupts are reconfigured at the PCI
    >> transport layer immediately before or after the device is put into the
    >> PCI PM D3 low power state.
    >> ---
    >> transport-pci.tex | 51 +++++++++++++++++++++++++++++++++++++++++++++++
    >> 1 file changed, 51 insertions(+)
    >>
    >> diff --git a/transport-pci.tex b/transport-pci.tex
    >> index a5c6719ea871..ce77708a9b69 100644
    >> --- a/transport-pci.tex
    >> +++ b/transport-pci.tex
    >> @@ -188,6 +188,8 @@ \subsection{Virtio Structure PCI Capabilities}\label{sec:Virtio Transport Option
    >> #define VIRTIO_PCI_CAP_SHARED_MEMORY_CFG 8
    >> /* Vendor-specific data */
    >> #define VIRTIO_PCI_CAP_VENDOR_CFG 9
    >> +/* Power management configuration */
    >> +#define VIRTIO_PCI_CAP_PM_CFG 10
    >> \end{lstlisting}
    >>
    >> Any other value is reserved for future use.
    >> @@ -804,6 +806,55 @@ \subsubsection{PCI configuration access capability}\label{sec:Virtio Transport O
    >> specified by some other Virtio Structure PCI Capability
    >> of type other than \field{VIRTIO_PCI_CAP_PCI_CFG}.
    >>
    >> +\subsubsection{Power management capability}\label{sec:Virtio Transport Options / Virtio Over PCI Bus / PCI Device Layout / Power management capability}
    >> +
    >> +The VIRTIO_PCI_CAP_PM_CFG capability refers to a single byte. The
    >> +driver can write to the byte to set the power state of the device,
    >> +and it can read from the byte to get the current power state of the
    >> +device.
    >> +
    >> +The valid power states are:
    >> +
    >> +\begin{lstlisting}
    >> +/* Device is operating normally */
    >> +#define VIRTIO_PM_STATE_ACTIVE 0
    >> +/* Device operation is suspended */
    >> +#define VIRTIO_PM_STATE_SUSPENDED 1
    >> +\end{lstlisting}
    >> +
    >> +The device power state has no effect when \field{device status} does
    >> +not have the DRIVER_OK bit set or does have the DEVICE_NEEDS_RESET bit
    >> +set.
    >
    > Given this is only after DRIVER_OK, wouldn't a feature bit + status bit
    > make more sense? This will make it transport-independent and simplify
    > discovery.
    I agree with Michael, I have ever proposed a solution suspending the device
    by setting _SUSPEND in the device_status field. I will send this suspending
    patch again(will cc you) in a few days.

    Thanks
    Zhu Lingshan
    >
    >> +\devicenormative{\paragraph}{Power management capability}{Virtio Transport Options / Virtio Over PCI Bus / PCI Device Layout / Power management capability}
    >> +
    >> +A device MUST maintain its state while suspended such that all driver
    >> +visible state after resuming exactly matches driver visible state
    >> +before suspending.
    >> +
    >> +A device MUST NOT send notifications while suspended.
    >> +
    >> +A device MAY operate on any buffers in its virtqueue while suspended.
    > How is this reconsiled with state matching exactly? buffers are
    > driver-visible ...
    >
    >> +A device MUST set its power state to VIRTIO_PM_STATE_ACTIVE on reset.
    >> +
    >> +A device SHOULD take steps to minimize its resource consumption while
    >> +suspended, although what this involves is specific to the particular
    >> +device implementation.
    >> +
    >> +\drivernormative{\paragraph}{Power management capability}{Virtio Transport Options / Virtio Over PCI Bus / PCI Device Layout / Power management capability}
    >> +
    >> +A driver MUST NOT access a suspended device's BARs corresponding to
    >> +any virtio structures, except for the power management byte.
    >> +
    >> +A driver MAY suspend a device that has buffers in one of its
    >> +virtqueues, but it MUST NOT modify any such buffers while the device
    >> +is suspended.
    >> +
    >> +A driver MUST read from the power management byte after writing to the
    >> +byte to verify that the device successfully entered the target power
    >> +state.
    > Verify how? By checking the value returned? And what should it do with the value
    > does not match?
    >
    >
    >> +
    >> \subsubsection{Legacy Interfaces: A Note on PCI Device Layout}\label{sec:Virtio Transport Options / Virtio Over PCI Bus / PCI Device Layout / Legacy Interfaces: A Note on PCI Device Layout}
    >>
    >> Transitional devices MUST present part of configuration
    >> --
    >> 2.44.0.rc0.258.g7320e95886-goog
    >
    > ---------------------------------------------------------------------
    > To unsubscribe, e-mail: virtio-dev-unsubscribe@lists.oasis-open.org
    > For additional commands, e-mail: virtio-dev-help@lists.oasis-open.org
    >




  • 5.  Re: [virtio-dev] Re: [PATCH v4 1/1] Add suspend support for virtio PCI devices

    Posted 02-18-2024 10:59


    On 2/16/2024 4:56 PM, Michael S. Tsirkin wrote:
    > On Fri, Feb 16, 2024 at 05:24:32PM +0900, David Stevens wrote:
    >> Add a virtio power management PCI capability to allow drivers to suspend
    >> virtio PCI devices. This allows drivers to suspend devices at the virtio
    >> level before suspending them at the PCI transport layer. This allows
    >> drivers to do a two phase suspend, which prevents notifications from
    >> being ignored or lost if interrupts are reconfigured at the PCI
    >> transport layer immediately before or after the device is put into the
    >> PCI PM D3 low power state.
    >> ---
    >> transport-pci.tex | 51 +++++++++++++++++++++++++++++++++++++++++++++++
    >> 1 file changed, 51 insertions(+)
    >>
    >> diff --git a/transport-pci.tex b/transport-pci.tex
    >> index a5c6719ea871..ce77708a9b69 100644
    >> --- a/transport-pci.tex
    >> +++ b/transport-pci.tex
    >> @@ -188,6 +188,8 @@ \subsection{Virtio Structure PCI Capabilities}\label{sec:Virtio Transport Option
    >> #define VIRTIO_PCI_CAP_SHARED_MEMORY_CFG 8
    >> /* Vendor-specific data */
    >> #define VIRTIO_PCI_CAP_VENDOR_CFG 9
    >> +/* Power management configuration */
    >> +#define VIRTIO_PCI_CAP_PM_CFG 10
    >> \end{lstlisting}
    >>
    >> Any other value is reserved for future use.
    >> @@ -804,6 +806,55 @@ \subsubsection{PCI configuration access capability}\label{sec:Virtio Transport O
    >> specified by some other Virtio Structure PCI Capability
    >> of type other than \field{VIRTIO_PCI_CAP_PCI_CFG}.
    >>
    >> +\subsubsection{Power management capability}\label{sec:Virtio Transport Options / Virtio Over PCI Bus / PCI Device Layout / Power management capability}
    >> +
    >> +The VIRTIO_PCI_CAP_PM_CFG capability refers to a single byte. The
    >> +driver can write to the byte to set the power state of the device,
    >> +and it can read from the byte to get the current power state of the
    >> +device.
    >> +
    >> +The valid power states are:
    >> +
    >> +\begin{lstlisting}
    >> +/* Device is operating normally */
    >> +#define VIRTIO_PM_STATE_ACTIVE 0
    >> +/* Device operation is suspended */
    >> +#define VIRTIO_PM_STATE_SUSPENDED 1
    >> +\end{lstlisting}
    >> +
    >> +The device power state has no effect when \field{device status} does
    >> +not have the DRIVER_OK bit set or does have the DEVICE_NEEDS_RESET bit
    >> +set.
    >
    > Given this is only after DRIVER_OK, wouldn't a feature bit + status bit
    > make more sense? This will make it transport-independent and simplify
    > discovery.
    I agree with Michael, I have ever proposed a solution suspending the device
    by setting _SUSPEND in the device_status field. I will send this suspending
    patch again(will cc you) in a few days.

    Thanks
    Zhu Lingshan
    >
    >> +\devicenormative{\paragraph}{Power management capability}{Virtio Transport Options / Virtio Over PCI Bus / PCI Device Layout / Power management capability}
    >> +
    >> +A device MUST maintain its state while suspended such that all driver
    >> +visible state after resuming exactly matches driver visible state
    >> +before suspending.
    >> +
    >> +A device MUST NOT send notifications while suspended.
    >> +
    >> +A device MAY operate on any buffers in its virtqueue while suspended.
    > How is this reconsiled with state matching exactly? buffers are
    > driver-visible ...
    >
    >> +A device MUST set its power state to VIRTIO_PM_STATE_ACTIVE on reset.
    >> +
    >> +A device SHOULD take steps to minimize its resource consumption while
    >> +suspended, although what this involves is specific to the particular
    >> +device implementation.
    >> +
    >> +\drivernormative{\paragraph}{Power management capability}{Virtio Transport Options / Virtio Over PCI Bus / PCI Device Layout / Power management capability}
    >> +
    >> +A driver MUST NOT access a suspended device's BARs corresponding to
    >> +any virtio structures, except for the power management byte.
    >> +
    >> +A driver MAY suspend a device that has buffers in one of its
    >> +virtqueues, but it MUST NOT modify any such buffers while the device
    >> +is suspended.
    >> +
    >> +A driver MUST read from the power management byte after writing to the
    >> +byte to verify that the device successfully entered the target power
    >> +state.
    > Verify how? By checking the value returned? And what should it do with the value
    > does not match?
    >
    >
    >> +
    >> \subsubsection{Legacy Interfaces: A Note on PCI Device Layout}\label{sec:Virtio Transport Options / Virtio Over PCI Bus / PCI Device Layout / Legacy Interfaces: A Note on PCI Device Layout}
    >>
    >> Transitional devices MUST present part of configuration
    >> --
    >> 2.44.0.rc0.258.g7320e95886-goog
    >
    > ---------------------------------------------------------------------
    > To unsubscribe, e-mail: virtio-dev-unsubscribe@lists.oasis-open.org
    > For additional commands, e-mail: virtio-dev-help@lists.oasis-open.org
    >




  • 6.  Re: [PATCH v4 1/1] Add suspend support for virtio PCI devices

    Posted 02-19-2024 06:47
    On Fri, Feb 16, 2024 at 5:56?PM Michael S. Tsirkin <mst@redhat.com> wrote:
    >
    > On Fri, Feb 16, 2024 at 05:24:32PM +0900, David Stevens wrote:
    > > Add a virtio power management PCI capability to allow drivers to suspend
    > > virtio PCI devices. This allows drivers to suspend devices at the virtio
    > > level before suspending them at the PCI transport layer. This allows
    > > drivers to do a two phase suspend, which prevents notifications from
    > > being ignored or lost if interrupts are reconfigured at the PCI
    > > transport layer immediately before or after the device is put into the
    > > PCI PM D3 low power state.
    > > ---
    > > transport-pci.tex | 51 +++++++++++++++++++++++++++++++++++++++++++++++
    > > 1 file changed, 51 insertions(+)
    > >
    > > diff --git a/transport-pci.tex b/transport-pci.tex
    > > index a5c6719ea871..ce77708a9b69 100644
    > > --- a/transport-pci.tex
    > > +++ b/transport-pci.tex
    > > @@ -188,6 +188,8 @@ \subsection{Virtio Structure PCI Capabilities}\label{sec:Virtio Transport Option
    > > #define VIRTIO_PCI_CAP_SHARED_MEMORY_CFG 8
    > > /* Vendor-specific data */
    > > #define VIRTIO_PCI_CAP_VENDOR_CFG 9
    > > +/* Power management configuration */
    > > +#define VIRTIO_PCI_CAP_PM_CFG 10
    > > \end{lstlisting}
    > >
    > > Any other value is reserved for future use.
    > > @@ -804,6 +806,55 @@ \subsubsection{PCI configuration access capability}\label{sec:Virtio Transport O
    > > specified by some other Virtio Structure PCI Capability
    > > of type other than \field{VIRTIO_PCI_CAP_PCI_CFG}.
    > >
    > > +\subsubsection{Power management capability}\label{sec:Virtio Transport Options / Virtio Over PCI Bus / PCI Device Layout / Power management capability}
    > > +
    > > +The VIRTIO_PCI_CAP_PM_CFG capability refers to a single byte. The
    > > +driver can write to the byte to set the power state of the device,
    > > +and it can read from the byte to get the current power state of the
    > > +device.
    > > +
    > > +The valid power states are:
    > > +
    > > +\begin{lstlisting}
    > > +/* Device is operating normally */
    > > +#define VIRTIO_PM_STATE_ACTIVE 0
    > > +/* Device operation is suspended */
    > > +#define VIRTIO_PM_STATE_SUSPENDED 1
    > > +\end{lstlisting}
    > > +
    > > +The device power state has no effect when \field{device status} does
    > > +not have the DRIVER_OK bit set or does have the DEVICE_NEEDS_RESET bit
    > > +set.
    >
    >
    > Given this is only after DRIVER_OK, wouldn't a feature bit + status bit
    > make more sense? This will make it transport-independent and simplify
    > discovery.

    A feature bit + status bit would work as well. I've posted some
    questions on Zhu Lingshan's patch.

    > > +\devicenormative{\paragraph}{Power management capability}{Virtio Transport Options / Virtio Over PCI Bus / PCI Device Layout / Power management capability}
    > > +
    > > +A device MUST maintain its state while suspended such that all driver
    > > +visible state after resuming exactly matches driver visible state
    > > +before suspending.
    > > +
    > > +A device MUST NOT send notifications while suspended.
    > > +
    > > +A device MAY operate on any buffers in its virtqueue while suspended.
    >
    > How is this reconsiled with state matching exactly? buffers are
    > driver-visible ...

    Drivers can't atomically access buffers and the PM byte, so the device
    modifying a buffer while suspended is indistinguishable from the
    device modifying a buffer in the window between when it is resumed by
    the driver and when the driver accesses the buffer. But you are right
    that the wording is contradictory. Maybe the earlier requirement could
    be better phrased as:

    A device MUST maintain its state while suspended such that after the
    driver resumes the device, the driver can use the device as if it had
    never been suspended in the first place.

    > > +A device MUST set its power state to VIRTIO_PM_STATE_ACTIVE on reset.
    > > +
    > > +A device SHOULD take steps to minimize its resource consumption while
    > > +suspended, although what this involves is specific to the particular
    > > +device implementation.
    > > +
    > > +\drivernormative{\paragraph}{Power management capability}{Virtio Transport Options / Virtio Over PCI Bus / PCI Device Layout / Power management capability}
    > > +
    > > +A driver MUST NOT access a suspended device's BARs corresponding to
    > > +any virtio structures, except for the power management byte.
    > > +
    > > +A driver MAY suspend a device that has buffers in one of its
    > > +virtqueues, but it MUST NOT modify any such buffers while the device
    > > +is suspended.
    > > +
    > > +A driver MUST read from the power management byte after writing to the
    > > +byte to verify that the device successfully entered the target power
    > > +state.
    >
    > Verify how? By checking the value returned? And what should it do with the value
    > does not match?

    Yes, comparing the value returned to the one it just wrote. The three
    options I can think of would be to abort the suspend, reset the
    device, or retry. Retry only makes sense if suspend/resume might
    succeed in the future. An API is really only retry-friendly if it has
    a way to set a timeout, since the consumer is what should be deciding
    how long to wait but can't make that decision without a timeout.
    Personally, I would lean towards not allowing timeouts here, since
    it's simpler. So maybe something like this:

    After the driver writes a new value to the PM byte, if the device can
    transition to the requested state, then subsequent reads of the PM
    state byte MUST block until the transition completes. If the device
    cannot transition to the requested state, it MUST immediately return
    the prior value of the PM state byte for subsequent reads of the PM
    state byte.

    In that case, the only options are to abort the suspension or to reset
    the device. That's really a policy decision of the driver, so I don't
    know how it would fit into this spec.

    -David


    -David



  • 7.  Re: [PATCH v4 1/1] Add suspend support for virtio PCI devices

    Posted 02-19-2024 07:42
    On Mon, Feb 19, 2024 at 03:46:37PM +0900, David Stevens wrote:
    > On Fri, Feb 16, 2024 at 5:56?PM Michael S. Tsirkin <mst@redhat.com> wrote:
    > >
    > > On Fri, Feb 16, 2024 at 05:24:32PM +0900, David Stevens wrote:
    > > > Add a virtio power management PCI capability to allow drivers to suspend
    > > > virtio PCI devices. This allows drivers to suspend devices at the virtio
    > > > level before suspending them at the PCI transport layer. This allows
    > > > drivers to do a two phase suspend, which prevents notifications from
    > > > being ignored or lost if interrupts are reconfigured at the PCI
    > > > transport layer immediately before or after the device is put into the
    > > > PCI PM D3 low power state.
    > > > ---
    > > > transport-pci.tex | 51 +++++++++++++++++++++++++++++++++++++++++++++++
    > > > 1 file changed, 51 insertions(+)
    > > >
    > > > diff --git a/transport-pci.tex b/transport-pci.tex
    > > > index a5c6719ea871..ce77708a9b69 100644
    > > > --- a/transport-pci.tex
    > > > +++ b/transport-pci.tex
    > > > @@ -188,6 +188,8 @@ \subsection{Virtio Structure PCI Capabilities}\label{sec:Virtio Transport Option
    > > > #define VIRTIO_PCI_CAP_SHARED_MEMORY_CFG 8
    > > > /* Vendor-specific data */
    > > > #define VIRTIO_PCI_CAP_VENDOR_CFG 9
    > > > +/* Power management configuration */
    > > > +#define VIRTIO_PCI_CAP_PM_CFG 10
    > > > \end{lstlisting}
    > > >
    > > > Any other value is reserved for future use.
    > > > @@ -804,6 +806,55 @@ \subsubsection{PCI configuration access capability}\label{sec:Virtio Transport O
    > > > specified by some other Virtio Structure PCI Capability
    > > > of type other than \field{VIRTIO_PCI_CAP_PCI_CFG}.
    > > >
    > > > +\subsubsection{Power management capability}\label{sec:Virtio Transport Options / Virtio Over PCI Bus / PCI Device Layout / Power management capability}
    > > > +
    > > > +The VIRTIO_PCI_CAP_PM_CFG capability refers to a single byte. The
    > > > +driver can write to the byte to set the power state of the device,
    > > > +and it can read from the byte to get the current power state of the
    > > > +device.
    > > > +
    > > > +The valid power states are:
    > > > +
    > > > +\begin{lstlisting}
    > > > +/* Device is operating normally */
    > > > +#define VIRTIO_PM_STATE_ACTIVE 0
    > > > +/* Device operation is suspended */
    > > > +#define VIRTIO_PM_STATE_SUSPENDED 1
    > > > +\end{lstlisting}
    > > > +
    > > > +The device power state has no effect when \field{device status} does
    > > > +not have the DRIVER_OK bit set or does have the DEVICE_NEEDS_RESET bit
    > > > +set.
    > >
    > >
    > > Given this is only after DRIVER_OK, wouldn't a feature bit + status bit
    > > make more sense? This will make it transport-independent and simplify
    > > discovery.
    >
    > A feature bit + status bit would work as well. I've posted some
    > questions on Zhu Lingshan's patch.


    Thanks! I like it that your patch is more specific but maybe something
    can be figure out to get the best of both worlds.

    > > > +\devicenormative{\paragraph}{Power management capability}{Virtio Transport Options / Virtio Over PCI Bus / PCI Device Layout / Power management capability}
    > > > +
    > > > +A device MUST maintain its state while suspended such that all driver
    > > > +visible state after resuming exactly matches driver visible state
    > > > +before suspending.
    > > > +
    > > > +A device MUST NOT send notifications while suspended.
    > > > +
    > > > +A device MAY operate on any buffers in its virtqueue while suspended.
    > >
    > > How is this reconsiled with state matching exactly? buffers are
    > > driver-visible ...
    >
    > Drivers can't atomically access buffers and the PM byte, so the device
    > modifying a buffer while suspended is indistinguishable from the
    > device modifying a buffer in the window between when it is resumed by
    > the driver and when the driver accesses the buffer. But you are right
    > that the wording is contradictory. Maybe the earlier requirement could
    > be better phrased as:
    >
    > A device MUST maintain its state while suspended such that after the
    > driver resumes the device, the driver can use the device as if it had
    > never been suspended in the first place.


    I think you wording is fine, just make it clear how is the
    contradiction resolved. E.g. exactly matches ... with the
    exception of using buffers available in one of the virtqueues.

    > > > +A device MUST set its power state to VIRTIO_PM_STATE_ACTIVE on reset.
    > > > +
    > > > +A device SHOULD take steps to minimize its resource consumption while
    > > > +suspended, although what this involves is specific to the particular
    > > > +device implementation.
    > > > +
    > > > +\drivernormative{\paragraph}{Power management capability}{Virtio Transport Options / Virtio Over PCI Bus / PCI Device Layout / Power management capability}
    > > > +
    > > > +A driver MUST NOT access a suspended device's BARs corresponding to
    > > > +any virtio structures, except for the power management byte.
    > > > +
    > > > +A driver MAY suspend a device that has buffers in one of its
    > > > +virtqueues, but it MUST NOT modify any such buffers while the device
    > > > +is suspended.
    > > > +
    > > > +A driver MUST read from the power management byte after writing to the
    > > > +byte to verify that the device successfully entered the target power
    > > > +state.
    > >
    > > Verify how? By checking the value returned? And what should it do with the value
    > > does not match?
    >
    > Yes, comparing the value returned to the one it just wrote. The three
    > options I can think of would be to abort the suspend, reset the
    > device, or retry. Retry only makes sense if suspend/resume might
    > succeed in the future.

    Well actually there is a reason to retry even without a timeout -
    has to do with pci rules which limit how quickly device has
    to respond to a read. So if you want to implement suspend
    in firmware and not be bound to any timing limits you need
    retry in software.


    > An API is really only retry-friendly if it has
    > a way to set a timeout, since the consumer is what should be deciding
    > how long to wait but can't make that decision without a timeout.
    > Personally, I would lean towards not allowing timeouts here, since
    > it's simpler. So maybe something like this:
    >
    > After the driver writes a new value to the PM byte, if the device can
    > transition to the requested state, then subsequent reads of the PM
    > state byte MUST block until the transition completes. If the device
    > cannot transition to the requested state, it MUST immediately return
    > the prior value of the PM state byte for subsequent reads of the PM
    > state byte.

    PCI has timing limitations on how long reads can block though.
    So that could be a reason to retry.


    > In that case, the only options are to abort the suspension or to reset
    > the device. That's really a policy decision of the driver, so I don't
    > know how it would fit into this spec.
    >
    > -David
    >
    >
    > -David




  • 8.  Re: [PATCH v4 1/1] Add suspend support for virtio PCI devices

    Posted 02-19-2024 07:42
    On Mon, Feb 19, 2024 at 03:46:37PM +0900, David Stevens wrote:
    > On Fri, Feb 16, 2024 at 5:56?PM Michael S. Tsirkin <mst@redhat.com> wrote:
    > >
    > > On Fri, Feb 16, 2024 at 05:24:32PM +0900, David Stevens wrote:
    > > > Add a virtio power management PCI capability to allow drivers to suspend
    > > > virtio PCI devices. This allows drivers to suspend devices at the virtio
    > > > level before suspending them at the PCI transport layer. This allows
    > > > drivers to do a two phase suspend, which prevents notifications from
    > > > being ignored or lost if interrupts are reconfigured at the PCI
    > > > transport layer immediately before or after the device is put into the
    > > > PCI PM D3 low power state.
    > > > ---
    > > > transport-pci.tex | 51 +++++++++++++++++++++++++++++++++++++++++++++++
    > > > 1 file changed, 51 insertions(+)
    > > >
    > > > diff --git a/transport-pci.tex b/transport-pci.tex
    > > > index a5c6719ea871..ce77708a9b69 100644
    > > > --- a/transport-pci.tex
    > > > +++ b/transport-pci.tex
    > > > @@ -188,6 +188,8 @@ \subsection{Virtio Structure PCI Capabilities}\label{sec:Virtio Transport Option
    > > > #define VIRTIO_PCI_CAP_SHARED_MEMORY_CFG 8
    > > > /* Vendor-specific data */
    > > > #define VIRTIO_PCI_CAP_VENDOR_CFG 9
    > > > +/* Power management configuration */
    > > > +#define VIRTIO_PCI_CAP_PM_CFG 10
    > > > \end{lstlisting}
    > > >
    > > > Any other value is reserved for future use.
    > > > @@ -804,6 +806,55 @@ \subsubsection{PCI configuration access capability}\label{sec:Virtio Transport O
    > > > specified by some other Virtio Structure PCI Capability
    > > > of type other than \field{VIRTIO_PCI_CAP_PCI_CFG}.
    > > >
    > > > +\subsubsection{Power management capability}\label{sec:Virtio Transport Options / Virtio Over PCI Bus / PCI Device Layout / Power management capability}
    > > > +
    > > > +The VIRTIO_PCI_CAP_PM_CFG capability refers to a single byte. The
    > > > +driver can write to the byte to set the power state of the device,
    > > > +and it can read from the byte to get the current power state of the
    > > > +device.
    > > > +
    > > > +The valid power states are:
    > > > +
    > > > +\begin{lstlisting}
    > > > +/* Device is operating normally */
    > > > +#define VIRTIO_PM_STATE_ACTIVE 0
    > > > +/* Device operation is suspended */
    > > > +#define VIRTIO_PM_STATE_SUSPENDED 1
    > > > +\end{lstlisting}
    > > > +
    > > > +The device power state has no effect when \field{device status} does
    > > > +not have the DRIVER_OK bit set or does have the DEVICE_NEEDS_RESET bit
    > > > +set.
    > >
    > >
    > > Given this is only after DRIVER_OK, wouldn't a feature bit + status bit
    > > make more sense? This will make it transport-independent and simplify
    > > discovery.
    >
    > A feature bit + status bit would work as well. I've posted some
    > questions on Zhu Lingshan's patch.


    Thanks! I like it that your patch is more specific but maybe something
    can be figure out to get the best of both worlds.

    > > > +\devicenormative{\paragraph}{Power management capability}{Virtio Transport Options / Virtio Over PCI Bus / PCI Device Layout / Power management capability}
    > > > +
    > > > +A device MUST maintain its state while suspended such that all driver
    > > > +visible state after resuming exactly matches driver visible state
    > > > +before suspending.
    > > > +
    > > > +A device MUST NOT send notifications while suspended.
    > > > +
    > > > +A device MAY operate on any buffers in its virtqueue while suspended.
    > >
    > > How is this reconsiled with state matching exactly? buffers are
    > > driver-visible ...
    >
    > Drivers can't atomically access buffers and the PM byte, so the device
    > modifying a buffer while suspended is indistinguishable from the
    > device modifying a buffer in the window between when it is resumed by
    > the driver and when the driver accesses the buffer. But you are right
    > that the wording is contradictory. Maybe the earlier requirement could
    > be better phrased as:
    >
    > A device MUST maintain its state while suspended such that after the
    > driver resumes the device, the driver can use the device as if it had
    > never been suspended in the first place.


    I think you wording is fine, just make it clear how is the
    contradiction resolved. E.g. exactly matches ... with the
    exception of using buffers available in one of the virtqueues.

    > > > +A device MUST set its power state to VIRTIO_PM_STATE_ACTIVE on reset.
    > > > +
    > > > +A device SHOULD take steps to minimize its resource consumption while
    > > > +suspended, although what this involves is specific to the particular
    > > > +device implementation.
    > > > +
    > > > +\drivernormative{\paragraph}{Power management capability}{Virtio Transport Options / Virtio Over PCI Bus / PCI Device Layout / Power management capability}
    > > > +
    > > > +A driver MUST NOT access a suspended device's BARs corresponding to
    > > > +any virtio structures, except for the power management byte.
    > > > +
    > > > +A driver MAY suspend a device that has buffers in one of its
    > > > +virtqueues, but it MUST NOT modify any such buffers while the device
    > > > +is suspended.
    > > > +
    > > > +A driver MUST read from the power management byte after writing to the
    > > > +byte to verify that the device successfully entered the target power
    > > > +state.
    > >
    > > Verify how? By checking the value returned? And what should it do with the value
    > > does not match?
    >
    > Yes, comparing the value returned to the one it just wrote. The three
    > options I can think of would be to abort the suspend, reset the
    > device, or retry. Retry only makes sense if suspend/resume might
    > succeed in the future.

    Well actually there is a reason to retry even without a timeout -
    has to do with pci rules which limit how quickly device has
    to respond to a read. So if you want to implement suspend
    in firmware and not be bound to any timing limits you need
    retry in software.


    > An API is really only retry-friendly if it has
    > a way to set a timeout, since the consumer is what should be deciding
    > how long to wait but can't make that decision without a timeout.
    > Personally, I would lean towards not allowing timeouts here, since
    > it's simpler. So maybe something like this:
    >
    > After the driver writes a new value to the PM byte, if the device can
    > transition to the requested state, then subsequent reads of the PM
    > state byte MUST block until the transition completes. If the device
    > cannot transition to the requested state, it MUST immediately return
    > the prior value of the PM state byte for subsequent reads of the PM
    > state byte.

    PCI has timing limitations on how long reads can block though.
    So that could be a reason to retry.


    > In that case, the only options are to abort the suspension or to reset
    > the device. That's really a policy decision of the driver, so I don't
    > know how it would fit into this spec.
    >
    > -David
    >
    >
    > -David




  • 9.  Re: [PATCH v4 1/1] Add suspend support for virtio PCI devices

    Posted 02-19-2024 06:47
    On Fri, Feb 16, 2024 at 5:56?PM Michael S. Tsirkin <mst@redhat.com> wrote:
    >
    > On Fri, Feb 16, 2024 at 05:24:32PM +0900, David Stevens wrote:
    > > Add a virtio power management PCI capability to allow drivers to suspend
    > > virtio PCI devices. This allows drivers to suspend devices at the virtio
    > > level before suspending them at the PCI transport layer. This allows
    > > drivers to do a two phase suspend, which prevents notifications from
    > > being ignored or lost if interrupts are reconfigured at the PCI
    > > transport layer immediately before or after the device is put into the
    > > PCI PM D3 low power state.
    > > ---
    > > transport-pci.tex | 51 +++++++++++++++++++++++++++++++++++++++++++++++
    > > 1 file changed, 51 insertions(+)
    > >
    > > diff --git a/transport-pci.tex b/transport-pci.tex
    > > index a5c6719ea871..ce77708a9b69 100644
    > > --- a/transport-pci.tex
    > > +++ b/transport-pci.tex
    > > @@ -188,6 +188,8 @@ \subsection{Virtio Structure PCI Capabilities}\label{sec:Virtio Transport Option
    > > #define VIRTIO_PCI_CAP_SHARED_MEMORY_CFG 8
    > > /* Vendor-specific data */
    > > #define VIRTIO_PCI_CAP_VENDOR_CFG 9
    > > +/* Power management configuration */
    > > +#define VIRTIO_PCI_CAP_PM_CFG 10
    > > \end{lstlisting}
    > >
    > > Any other value is reserved for future use.
    > > @@ -804,6 +806,55 @@ \subsubsection{PCI configuration access capability}\label{sec:Virtio Transport O
    > > specified by some other Virtio Structure PCI Capability
    > > of type other than \field{VIRTIO_PCI_CAP_PCI_CFG}.
    > >
    > > +\subsubsection{Power management capability}\label{sec:Virtio Transport Options / Virtio Over PCI Bus / PCI Device Layout / Power management capability}
    > > +
    > > +The VIRTIO_PCI_CAP_PM_CFG capability refers to a single byte. The
    > > +driver can write to the byte to set the power state of the device,
    > > +and it can read from the byte to get the current power state of the
    > > +device.
    > > +
    > > +The valid power states are:
    > > +
    > > +\begin{lstlisting}
    > > +/* Device is operating normally */
    > > +#define VIRTIO_PM_STATE_ACTIVE 0
    > > +/* Device operation is suspended */
    > > +#define VIRTIO_PM_STATE_SUSPENDED 1
    > > +\end{lstlisting}
    > > +
    > > +The device power state has no effect when \field{device status} does
    > > +not have the DRIVER_OK bit set or does have the DEVICE_NEEDS_RESET bit
    > > +set.
    >
    >
    > Given this is only after DRIVER_OK, wouldn't a feature bit + status bit
    > make more sense? This will make it transport-independent and simplify
    > discovery.

    A feature bit + status bit would work as well. I've posted some
    questions on Zhu Lingshan's patch.

    > > +\devicenormative{\paragraph}{Power management capability}{Virtio Transport Options / Virtio Over PCI Bus / PCI Device Layout / Power management capability}
    > > +
    > > +A device MUST maintain its state while suspended such that all driver
    > > +visible state after resuming exactly matches driver visible state
    > > +before suspending.
    > > +
    > > +A device MUST NOT send notifications while suspended.
    > > +
    > > +A device MAY operate on any buffers in its virtqueue while suspended.
    >
    > How is this reconsiled with state matching exactly? buffers are
    > driver-visible ...

    Drivers can't atomically access buffers and the PM byte, so the device
    modifying a buffer while suspended is indistinguishable from the
    device modifying a buffer in the window between when it is resumed by
    the driver and when the driver accesses the buffer. But you are right
    that the wording is contradictory. Maybe the earlier requirement could
    be better phrased as:

    A device MUST maintain its state while suspended such that after the
    driver resumes the device, the driver can use the device as if it had
    never been suspended in the first place.

    > > +A device MUST set its power state to VIRTIO_PM_STATE_ACTIVE on reset.
    > > +
    > > +A device SHOULD take steps to minimize its resource consumption while
    > > +suspended, although what this involves is specific to the particular
    > > +device implementation.
    > > +
    > > +\drivernormative{\paragraph}{Power management capability}{Virtio Transport Options / Virtio Over PCI Bus / PCI Device Layout / Power management capability}
    > > +
    > > +A driver MUST NOT access a suspended device's BARs corresponding to
    > > +any virtio structures, except for the power management byte.
    > > +
    > > +A driver MAY suspend a device that has buffers in one of its
    > > +virtqueues, but it MUST NOT modify any such buffers while the device
    > > +is suspended.
    > > +
    > > +A driver MUST read from the power management byte after writing to the
    > > +byte to verify that the device successfully entered the target power
    > > +state.
    >
    > Verify how? By checking the value returned? And what should it do with the value
    > does not match?

    Yes, comparing the value returned to the one it just wrote. The three
    options I can think of would be to abort the suspend, reset the
    device, or retry. Retry only makes sense if suspend/resume might
    succeed in the future. An API is really only retry-friendly if it has
    a way to set a timeout, since the consumer is what should be deciding
    how long to wait but can't make that decision without a timeout.
    Personally, I would lean towards not allowing timeouts here, since
    it's simpler. So maybe something like this:

    After the driver writes a new value to the PM byte, if the device can
    transition to the requested state, then subsequent reads of the PM
    state byte MUST block until the transition completes. If the device
    cannot transition to the requested state, it MUST immediately return
    the prior value of the PM state byte for subsequent reads of the PM
    state byte.

    In that case, the only options are to abort the suspension or to reset
    the device. That's really a policy decision of the driver, so I don't
    know how it would fit into this spec.

    -David


    -David



  • 10.  Re: [PATCH v4 1/1] Add suspend support for virtio PCI devices

    Posted 02-16-2024 08:56
    On Fri, Feb 16, 2024 at 05:24:32PM +0900, David Stevens wrote:
    > Add a virtio power management PCI capability to allow drivers to suspend
    > virtio PCI devices. This allows drivers to suspend devices at the virtio
    > level before suspending them at the PCI transport layer. This allows
    > drivers to do a two phase suspend, which prevents notifications from
    > being ignored or lost if interrupts are reconfigured at the PCI
    > transport layer immediately before or after the device is put into the
    > PCI PM D3 low power state.
    > ---
    > transport-pci.tex | 51 +++++++++++++++++++++++++++++++++++++++++++++++
    > 1 file changed, 51 insertions(+)
    >
    > diff --git a/transport-pci.tex b/transport-pci.tex
    > index a5c6719ea871..ce77708a9b69 100644
    > --- a/transport-pci.tex
    > +++ b/transport-pci.tex
    > @@ -188,6 +188,8 @@ \subsection{Virtio Structure PCI Capabilities}\label{sec:Virtio Transport Option
    > #define VIRTIO_PCI_CAP_SHARED_MEMORY_CFG 8
    > /* Vendor-specific data */
    > #define VIRTIO_PCI_CAP_VENDOR_CFG 9
    > +/* Power management configuration */
    > +#define VIRTIO_PCI_CAP_PM_CFG 10
    > \end{lstlisting}
    >
    > Any other value is reserved for future use.
    > @@ -804,6 +806,55 @@ \subsubsection{PCI configuration access capability}\label{sec:Virtio Transport O
    > specified by some other Virtio Structure PCI Capability
    > of type other than \field{VIRTIO_PCI_CAP_PCI_CFG}.
    >
    > +\subsubsection{Power management capability}\label{sec:Virtio Transport Options / Virtio Over PCI Bus / PCI Device Layout / Power management capability}
    > +
    > +The VIRTIO_PCI_CAP_PM_CFG capability refers to a single byte. The
    > +driver can write to the byte to set the power state of the device,
    > +and it can read from the byte to get the current power state of the
    > +device.
    > +
    > +The valid power states are:
    > +
    > +\begin{lstlisting}
    > +/* Device is operating normally */
    > +#define VIRTIO_PM_STATE_ACTIVE 0
    > +/* Device operation is suspended */
    > +#define VIRTIO_PM_STATE_SUSPENDED 1
    > +\end{lstlisting}
    > +
    > +The device power state has no effect when \field{device status} does
    > +not have the DRIVER_OK bit set or does have the DEVICE_NEEDS_RESET bit
    > +set.


    Given this is only after DRIVER_OK, wouldn't a feature bit + status bit
    make more sense? This will make it transport-independent and simplify
    discovery.

    > +\devicenormative{\paragraph}{Power management capability}{Virtio Transport Options / Virtio Over PCI Bus / PCI Device Layout / Power management capability}
    > +
    > +A device MUST maintain its state while suspended such that all driver
    > +visible state after resuming exactly matches driver visible state
    > +before suspending.
    > +
    > +A device MUST NOT send notifications while suspended.
    > +
    > +A device MAY operate on any buffers in its virtqueue while suspended.

    How is this reconsiled with state matching exactly? buffers are
    driver-visible ...

    > +A device MUST set its power state to VIRTIO_PM_STATE_ACTIVE on reset.
    > +
    > +A device SHOULD take steps to minimize its resource consumption while
    > +suspended, although what this involves is specific to the particular
    > +device implementation.
    > +
    > +\drivernormative{\paragraph}{Power management capability}{Virtio Transport Options / Virtio Over PCI Bus / PCI Device Layout / Power management capability}
    > +
    > +A driver MUST NOT access a suspended device's BARs corresponding to
    > +any virtio structures, except for the power management byte.
    > +
    > +A driver MAY suspend a device that has buffers in one of its
    > +virtqueues, but it MUST NOT modify any such buffers while the device
    > +is suspended.
    > +
    > +A driver MUST read from the power management byte after writing to the
    > +byte to verify that the device successfully entered the target power
    > +state.

    Verify how? By checking the value returned? And what should it do with the value
    does not match?


    > +
    > \subsubsection{Legacy Interfaces: A Note on PCI Device Layout}\label{sec:Virtio Transport Options / Virtio Over PCI Bus / PCI Device Layout / Legacy Interfaces: A Note on PCI Device Layout}
    >
    > Transitional devices MUST present part of configuration
    > --
    > 2.44.0.rc0.258.g7320e95886-goog




  • 11.  [PATCH v4 1/1] Add suspend support for virtio PCI devices

    Posted 02-16-2024 08:25
    Add a virtio power management PCI capability to allow drivers to suspend
    virtio PCI devices. This allows drivers to suspend devices at the virtio
    level before suspending them at the PCI transport layer. This allows
    drivers to do a two phase suspend, which prevents notifications from
    being ignored or lost if interrupts are reconfigured at the PCI
    transport layer immediately before or after the device is put into the
    PCI PM D3 low power state.
    ---
    transport-pci.tex | 51 +++++++++++++++++++++++++++++++++++++++++++++++
    1 file changed, 51 insertions(+)

    diff --git a/transport-pci.tex b/transport-pci.tex
    index a5c6719ea871..ce77708a9b69 100644
    --- a/transport-pci.tex
    +++ b/transport-pci.tex
    @@ -188,6 +188,8 @@ \subsection{Virtio Structure PCI Capabilities}\label{sec:Virtio Transport Option
    #define VIRTIO_PCI_CAP_SHARED_MEMORY_CFG 8
    /* Vendor-specific data */
    #define VIRTIO_PCI_CAP_VENDOR_CFG 9
    +/* Power management configuration */
    +#define VIRTIO_PCI_CAP_PM_CFG 10
    \end{lstlisting}

    Any other value is reserved for future use.
    @@ -804,6 +806,55 @@ \subsubsection{PCI configuration access capability}\label{sec:Virtio Transport O
    specified by some other Virtio Structure PCI Capability
    of type other than \field{VIRTIO_PCI_CAP_PCI_CFG}.

    +\subsubsection{Power management capability}\label{sec:Virtio Transport Options / Virtio Over PCI Bus / PCI Device Layout / Power management capability}
    +
    +The VIRTIO_PCI_CAP_PM_CFG capability refers to a single byte. The
    +driver can write to the byte to set the power state of the device,
    +and it can read from the byte to get the current power state of the
    +device.
    +
    +The valid power states are:
    +
    +\begin{lstlisting}
    +/* Device is operating normally */
    +#define VIRTIO_PM_STATE_ACTIVE 0
    +/* Device operation is suspended */
    +#define VIRTIO_PM_STATE_SUSPENDED 1
    +\end{lstlisting}
    +
    +The device power state has no effect when \field{device status} does
    +not have the DRIVER_OK bit set or does have the DEVICE_NEEDS_RESET bit
    +set.
    +
    +\devicenormative{\paragraph}{Power management capability}{Virtio Transport Options / Virtio Over PCI Bus / PCI Device Layout / Power management capability}
    +
    +A device MUST maintain its state while suspended such that all driver
    +visible state after resuming exactly matches driver visible state
    +before suspending.
    +
    +A device MUST NOT send notifications while suspended.
    +
    +A device MAY operate on any buffers in its virtqueue while suspended.
    +
    +A device MUST set its power state to VIRTIO_PM_STATE_ACTIVE on reset.
    +
    +A device SHOULD take steps to minimize its resource consumption while
    +suspended, although what this involves is specific to the particular
    +device implementation.
    +
    +\drivernormative{\paragraph}{Power management capability}{Virtio Transport Options / Virtio Over PCI Bus / PCI Device Layout / Power management capability}
    +
    +A driver MUST NOT access a suspended device's BARs corresponding to
    +any virtio structures, except for the power management byte.
    +
    +A driver MAY suspend a device that has buffers in one of its
    +virtqueues, but it MUST NOT modify any such buffers while the device
    +is suspended.
    +
    +A driver MUST read from the power management byte after writing to the
    +byte to verify that the device successfully entered the target power
    +state.
    +
    \subsubsection{Legacy Interfaces: A Note on PCI Device Layout}\label{sec:Virtio Transport Options / Virtio Over PCI Bus / PCI Device Layout / Legacy Interfaces: A Note on PCI Device Layout}

    Transitional devices MUST present part of configuration
    --
    2.44.0.rc0.258.g7320e95886-goog