PCI/VPD: Add runtime power management to sysfs interface
Unlike default access to config space through sysfs, the VPD read and write functions don't actively manage the runtime power management state of the device during access. Since commit 7ab5e10eda02 ("vfio/pci: Move the unused device into low power state with runtime PM"), the vfio-pci driver will use runtime power management and release unused devices to make use of low power states. Attempting to access VPD information in D3cold can result in incorrect information or kernel crashes depending on the system behavior. Wrap the VPD read/write bin attribute handlers in runtime PM and take into account the potential quirk to select the correct device to wake. Link: https://lore.kernel.org/r/20230803171233.3810944-2-alex.williamson@redhat.com Signed-off-by: Alex Williamson <alex.williamson@redhat.com> [bhelgaas: tweak pci_dev_put() test to match the pci_get_func0_dev() test] Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
This commit is contained in:
parent
06c2afb862
commit
5cd903bce9
@ -275,8 +275,23 @@ static ssize_t vpd_read(struct file *filp, struct kobject *kobj,
|
||||
size_t count)
|
||||
{
|
||||
struct pci_dev *dev = to_pci_dev(kobj_to_dev(kobj));
|
||||
struct pci_dev *vpd_dev = dev;
|
||||
ssize_t ret;
|
||||
|
||||
return pci_read_vpd(dev, off, count, buf);
|
||||
if (dev->dev_flags & PCI_DEV_FLAGS_VPD_REF_F0) {
|
||||
vpd_dev = pci_get_func0_dev(dev);
|
||||
if (!vpd_dev)
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
pci_config_pm_runtime_get(vpd_dev);
|
||||
ret = pci_read_vpd(vpd_dev, off, count, buf);
|
||||
pci_config_pm_runtime_put(vpd_dev);
|
||||
|
||||
if (dev->dev_flags & PCI_DEV_FLAGS_VPD_REF_F0)
|
||||
pci_dev_put(vpd_dev);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static ssize_t vpd_write(struct file *filp, struct kobject *kobj,
|
||||
@ -284,8 +299,23 @@ static ssize_t vpd_write(struct file *filp, struct kobject *kobj,
|
||||
size_t count)
|
||||
{
|
||||
struct pci_dev *dev = to_pci_dev(kobj_to_dev(kobj));
|
||||
struct pci_dev *vpd_dev = dev;
|
||||
ssize_t ret;
|
||||
|
||||
return pci_write_vpd(dev, off, count, buf);
|
||||
if (dev->dev_flags & PCI_DEV_FLAGS_VPD_REF_F0) {
|
||||
vpd_dev = pci_get_func0_dev(dev);
|
||||
if (!vpd_dev)
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
pci_config_pm_runtime_get(vpd_dev);
|
||||
ret = pci_write_vpd(vpd_dev, off, count, buf);
|
||||
pci_config_pm_runtime_put(vpd_dev);
|
||||
|
||||
if (dev->dev_flags & PCI_DEV_FLAGS_VPD_REF_F0)
|
||||
pci_dev_put(vpd_dev);
|
||||
|
||||
return ret;
|
||||
}
|
||||
static BIN_ATTR(vpd, 0600, vpd_read, vpd_write, 0);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user