lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Date:   Thu, 12 Aug 2021 11:37:27 -0600
From:   Alex Williamson <alex.williamson@...hat.com>
To:     alex.williamson@...hat.com
Cc:     linux-kernel@...r.kernel.org, kvm@...r.kernel.org
Subject: [PATCH] vfio_pci: Wake device to D0 before resets

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@...hat.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);


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ