Skip to content

Commit 70b70a4

Browse files
l1kbjorn-helgaas
authored andcommitted
PCI/sysfs: Protect driver's D3cold preference from user space
struct pci_dev contains two flags which govern whether the device may suspend to D3cold: * no_d3cold provides an opt-out for drivers (e.g. if a device is known to not wake from D3cold) * d3cold_allowed provides an opt-out for user space (default is true, user space may set to false) Since commit 9d26d3a ("PCI: Put PCIe ports into D3 during suspend"), the user space setting overwrites the driver setting. Essentially user space is trusted to know better than the driver whether D3cold is working. That feels unsafe and wrong. Assume that the change was introduced inadvertently and do not overwrite no_d3cold when d3cold_allowed is modified. Instead, consider d3cold_allowed in addition to no_d3cold when choosing a suspend state for the device. That way, user space may opt out of D3cold if the driver hasn't, but it may no longer force an opt in if the driver has opted out. Fixes: 9d26d3a ("PCI: Put PCIe ports into D3 during suspend") Link: https://lore.kernel.org/r/b8a7f4af2b73f6b506ad8ddee59d747cbf834606.1695025365.git.lukas@wunner.de Signed-off-by: Lukas Wunner <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]> Reviewed-by: Mika Westerberg <[email protected]> Reviewed-by: Mario Limonciello <[email protected]> Cc: [email protected] # v4.8+
1 parent 0bb80ec commit 70b70a4

File tree

2 files changed

+2
-5
lines changed

2 files changed

+2
-5
lines changed

drivers/pci/pci-acpi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,7 @@ pci_power_t acpi_pci_choose_state(struct pci_dev *pdev)
911911
{
912912
int acpi_state, d_max;
913913

914-
if (pdev->no_d3cold)
914+
if (pdev->no_d3cold || !pdev->d3cold_allowed)
915915
d_max = ACPI_STATE_D3_HOT;
916916
else
917917
d_max = ACPI_STATE_D3_COLD;

drivers/pci/pci-sysfs.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -530,10 +530,7 @@ static ssize_t d3cold_allowed_store(struct device *dev,
530530
return -EINVAL;
531531

532532
pdev->d3cold_allowed = !!val;
533-
if (pdev->d3cold_allowed)
534-
pci_d3cold_enable(pdev);
535-
else
536-
pci_d3cold_disable(pdev);
533+
pci_bridge_d3_update(pdev);
537534

538535
pm_runtime_resume(dev);
539536

0 commit comments

Comments
 (0)