From: Alex Williamson <alex.williamson@redhat.com>
To: alex.williamson@redhat.com
Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org
Subject: [PATCH] vfio_pci: Wake device to D0 before resets
Date: Thu, 12 Aug 2021 11:37:27 -0600 [thread overview]
Message-ID: <162878980049.119165.8034541463589403195.stgit@omen> (raw)
pci_pm_reset() actually depends on the device starting in the D0 power
state, therefore any time we're using a flavor of pci_reset_function()
we should make sure the device is fully powered-up in case the PM reset
method is used.
It's not uncommon that shutdown of a VM will put the device into a D3
state such that vfio_pci_disable() is managing a device in this low
power state. The reset state of a device is the D0 power state, so
it's also reasonable to put the device into this state prior to reset.
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
---
drivers/vfio/pci/vfio_pci.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c
index a4f44ea52fa3..e3faa1eb1a8c 100644
--- a/drivers/vfio/pci/vfio_pci.c
+++ b/drivers/vfio/pci/vfio_pci.c
@@ -454,6 +454,15 @@ static void vfio_pci_disable(struct vfio_pci_device *vdev)
vdev->needs_reset = true;
+ /*
+ * Userspace may have left the device in a low power state which
+ * affects our ability to trigger a PM reset, restore to D0 and
+ * toss any saved state from the previous session.
+ */
+ pci_set_power_state(pdev, PCI_D0);
+ kfree(vdev->pm_save);
+ vdev->pm_save = NULL;
+
/*
* If we have saved state, restore it. If we can reset the device,
* even better. Resetting with current state seems better than
@@ -1013,6 +1022,9 @@ static long vfio_pci_ioctl(struct vfio_device *core_vdev,
if (!vdev->reset_works)
return -EINVAL;
+ /* PM reset depends on the device not already being in D3 */
+ vfio_pci_set_power_state(vdev, PCI_D0);
+
vfio_pci_zap_and_down_write_memory_lock(vdev);
ret = pci_try_reset_function(vdev->pdev);
up_write(&vdev->memory_lock);
reply other threads:[~2021-08-12 17:37 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=162878980049.119165.8034541463589403195.stgit@omen \
--to=alex.williamson@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox