Skip to content

Commit 5cd903b

Browse files
awilliambjorn-helgaas
authored andcommitted
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 7ab5e10 ("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>
1 parent 06c2afb commit 5cd903b

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

drivers/pci/vpd.c

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,17 +275,47 @@ static ssize_t vpd_read(struct file *filp, struct kobject *kobj,
275275
size_t count)
276276
{
277277
struct pci_dev *dev = to_pci_dev(kobj_to_dev(kobj));
278+
struct pci_dev *vpd_dev = dev;
279+
ssize_t ret;
280+
281+
if (dev->dev_flags & PCI_DEV_FLAGS_VPD_REF_F0) {
282+
vpd_dev = pci_get_func0_dev(dev);
283+
if (!vpd_dev)
284+
return -ENODEV;
285+
}
286+
287+
pci_config_pm_runtime_get(vpd_dev);
288+
ret = pci_read_vpd(vpd_dev, off, count, buf);
289+
pci_config_pm_runtime_put(vpd_dev);
290+
291+
if (dev->dev_flags & PCI_DEV_FLAGS_VPD_REF_F0)
292+
pci_dev_put(vpd_dev);
278293

279-
return pci_read_vpd(dev, off, count, buf);
294+
return ret;
280295
}
281296

282297
static ssize_t vpd_write(struct file *filp, struct kobject *kobj,
283298
struct bin_attribute *bin_attr, char *buf, loff_t off,
284299
size_t count)
285300
{
286301
struct pci_dev *dev = to_pci_dev(kobj_to_dev(kobj));
302+
struct pci_dev *vpd_dev = dev;
303+
ssize_t ret;
304+
305+
if (dev->dev_flags & PCI_DEV_FLAGS_VPD_REF_F0) {
306+
vpd_dev = pci_get_func0_dev(dev);
307+
if (!vpd_dev)
308+
return -ENODEV;
309+
}
310+
311+
pci_config_pm_runtime_get(vpd_dev);
312+
ret = pci_write_vpd(vpd_dev, off, count, buf);
313+
pci_config_pm_runtime_put(vpd_dev);
314+
315+
if (dev->dev_flags & PCI_DEV_FLAGS_VPD_REF_F0)
316+
pci_dev_put(vpd_dev);
287317

288-
return pci_write_vpd(dev, off, count, buf);
318+
return ret;
289319
}
290320
static BIN_ATTR(vpd, 0600, vpd_read, vpd_write, 0);
291321

0 commit comments

Comments
 (0)