netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Qiang Zhang <qiang4.zhang@linux.intel.com>
To: Jason Wang <jasowang@redhat.com>
Cc: "Michael S. Tsirkin" <mst@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Stefan Hajnoczi" <stefanha@redhat.com>,
	"Eugenio Pérez" <eperezma@redhat.com>,
	"Xuan Zhuo" <xuanzhuo@linux.alibaba.com>,
	"Jens Axboe" <axboe@kernel.dk>,
	"Olivia Mackall" <olivia@selenic.com>,
	"Herbert Xu" <herbert@gondor.apana.org.au>,
	"Amit Shah" <amit@kernel.org>, "Arnd Bergmann" <arnd@arndb.de>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	Gonglei <arei.gonglei@huawei.com>,
	"David S. Miller" <davem@davemloft.net>,
	"Viresh Kumar" <viresh.kumar@linaro.org>,
	"Chen, Jian Jun" <jian.jun.chen@intel.com>,
	"Andi Shyti" <andi.shyti@kernel.org>,
	"Andrew Lunn" <andrew+netdev@lunn.ch>,
	"Eric Dumazet" <edumazet@google.com>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Paolo Abeni" <pabeni@redhat.com>,
	"James E.J. Bottomley" <James.Bottomley@hansenpartnership.com>,
	"Martin K. Petersen" <martin.petersen@oracle.com>,
	"David Hildenbrand" <david@redhat.com>,
	"Gerd Hoffmann" <kraxel@redhat.com>,
	"Anton Yakovlev" <anton.yakovlev@opensynergy.com>,
	"Jaroslav Kysela" <perex@perex.cz>,
	"Takashi Iwai" <tiwai@suse.com>,
	"Qiang Zhang" <qiang4.zhang@intel.com>,
	virtualization@lists.linux.dev, linux-block@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org,
	linux-i2c@vger.kernel.org, netdev@vger.kernel.org,
	linux-scsi@vger.kernel.org, linux-sound@vger.kernel.org
Subject: Re: [PATCH v2] virtio: only reset device and restore status if needed in device resume
Date: Fri, 1 Nov 2024 13:20:11 +0800	[thread overview]
Message-ID: <ZyRlC-5V_NTKgzXh@dev-qz> (raw)
In-Reply-To: <CACGkMEtvrBRd8BaeUiR6bm1xVX4KUGa83s03tPWPHB2U0mYfLA@mail.gmail.com>

On Fri, Nov 01, 2024 at 10:11:11AM +0800, Jason Wang wrote:
> On Fri, Nov 1, 2024 at 9:54 AM <qiang4.zhang@linux.intel.com> wrote:
> >
> > From: Qiang Zhang <qiang4.zhang@intel.com>
> >
> > Virtio core unconditionally reset and restore status for all virtio
> > devices before calling restore method. This breaks some virtio drivers
> > which don't need to do anything in suspend and resume because they
> > just want to keep device state retained.
> 
> The challenge is how can driver know device doesn't need rest.

Hi,

Per my understanding to PM, in the suspend flow, device drivers need to
1. First manage/stop accesses from upper level software and
2. Store the volatile context into in-memory data structures.
3. Put devices into some low power (suspended) state.
The resume process does the reverse.
If a device context won't loose after entering some low power state
(optional), it's OK to skip step 2.

For virtio devices, spec doesn't define whether their states will lost
after platform entering suspended state. So to work with different
hypervisors, virtio drivers typically trigger a reset in suspend/resume
flow. This works fine for virtio devices if following conditions are met:
- Device state can be totally recoverable.
- There isn't any working behaviour expected in suspended state, i.e. the
  suspended state should be sub-state of reset.
However, the first point may be hard to implement from driver side for some
devices. The second point may be unacceptable for some kind of devices.

For your question, for devices whose suspended state is alike reset state,
the hypervisor have the flexibility to retain its state or not, kernel
driver can unconditionally reset it with proper re-initialization to
accomplish better compatibility. For others, hypervisor *must* retain
device state and driver just keeps using it.

> 
> For example, PCI has no_soft_reset which has been done in the commit
> "virtio: Add support for no-reset virtio PCI PM".
> 
> And there's a ongoing long discussion of adding suspend support in the
> virtio spec, then driver know it's safe to suspend/resume without
> reset.

That's great! Hopefully it can fill the gap.
Currently, I think we can safely move the reset to drivers' freeze methods,
virtio core has no reason to take it as a common action required by all
devices. And the reset operation can be optional skipped if driver have
hints from device that it can retain state.

> 
> >
> > Virtio GPIO is a typical example. GPIO states should be kept unchanged
> > after suspend and resume (e.g. output pins keep driving the output) and
> > Virtio GPIO driver does nothing in freeze and restore methods. But the
> > reset operation in virtio_device_restore breaks this.
> 
> Is this mandated by GPIO or virtio spec? If yes, let's quote the revelant part.

No. But in actual hardware design (e.g. Intel PCH GPIO), or from the
requirement perspective, GPIO pin state can be (should support) retained
in suspended state.
If Virtio GPIO is used to let VM operate such physical GPIO chip indirectly,
it can't be reset in suspend and resume. Meanwhile the hypervisor will
retain pin states after suspension.

> 
> >
> > Since some devices need reset in suspend and resume while some needn't,
> > create a new helper function for the original reset and status restore
> > logic so that virtio drivers can invoke it in their restore method
> > if necessary.
> 
> How are those drivers classified?

I think this depends whether hypervisor will keep devices state in platform
suspend process. I think hypervisor should because suspend and reset are
conceptually two different things.


Thanks
Qiang

  reply	other threads:[~2024-11-01  5:22 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-31  3:08 [PATCH] virtio: only reset device and restore status if needed in device resume qiang4.zhang
2024-10-31 14:01 ` kernel test robot
2024-10-31 14:12 ` kernel test robot
2024-11-01  1:50 ` [PATCH v2] " qiang4.zhang
2024-11-01  2:11   ` Jason Wang
2024-11-01  5:20     ` Qiang Zhang [this message]
2024-11-05  3:09       ` Jason Wang
2024-11-06  9:28     ` Michael S. Tsirkin
2024-11-08  2:53       ` Jason Wang

Reply instructions:

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

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

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

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

  git send-email \
    --in-reply-to=ZyRlC-5V_NTKgzXh@dev-qz \
    --to=qiang4.zhang@linux.intel.com \
    --cc=James.Bottomley@hansenpartnership.com \
    --cc=amit@kernel.org \
    --cc=andi.shyti@kernel.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=anton.yakovlev@opensynergy.com \
    --cc=arei.gonglei@huawei.com \
    --cc=arnd@arndb.de \
    --cc=axboe@kernel.dk \
    --cc=davem@davemloft.net \
    --cc=david@redhat.com \
    --cc=edumazet@google.com \
    --cc=eperezma@redhat.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=herbert@gondor.apana.org.au \
    --cc=jasowang@redhat.com \
    --cc=jian.jun.chen@intel.com \
    --cc=kraxel@redhat.com \
    --cc=kuba@kernel.org \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=mst@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=olivia@selenic.com \
    --cc=pabeni@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=perex@perex.cz \
    --cc=qiang4.zhang@intel.com \
    --cc=stefanha@redhat.com \
    --cc=tiwai@suse.com \
    --cc=viresh.kumar@linaro.org \
    --cc=virtualization@lists.linux.dev \
    --cc=xuanzhuo@linux.alibaba.com \
    /path/to/YOUR_REPLY

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

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