* [PATCH] PCI: Make d3cold_allowed sysfs attribute read only
@ 2023-10-02 18:10 Mario Limonciello
2023-10-03 9:44 ` Mika Westerberg
0 siblings, 1 reply; 4+ messages in thread
From: Mario Limonciello @ 2023-10-02 18:10 UTC (permalink / raw)
To: bhelgaas, lukas
Cc: linux-kernel, linux-pci, mika.westerberg, Mario Limonciello
Before d3cold was stable userspace was allowed to influence the kernel's
decision of whether to enable d3cold for a device by a sysfs file
`d3cold_allowed`. This potentially allows userspace to break the suspend
for the system.
For debugging purposes `pci_port_pm=` can be used to control whether
a PCI port will go into D3cold and runtime PM can be turned off by
sysfs on PCI end points.
Change the sysfs attribute to read-only and simplify the internal kernel
logic to avoid needing to store the userspace request.
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
---
Documentation/ABI/testing/sysfs-bus-pci | 3 +--
drivers/pci/pci-acpi.c | 2 +-
drivers/pci/pci-sysfs.c | 22 ++--------------------
drivers/pci/pci.c | 3 +--
include/linux/pci.h | 1 -
5 files changed, 5 insertions(+), 26 deletions(-)
diff --git a/Documentation/ABI/testing/sysfs-bus-pci b/Documentation/ABI/testing/sysfs-bus-pci
index ecf47559f495..436e25cdf3ad 100644
--- a/Documentation/ABI/testing/sysfs-bus-pci
+++ b/Documentation/ABI/testing/sysfs-bus-pci
@@ -283,8 +283,7 @@ Description:
device will never be put into D3Cold state. If it is set, the
device may be put into D3Cold state if other requirements are
satisfied too. Reading this attribute will show the current
- value of d3cold_allowed bit. Writing this attribute will set
- the value of d3cold_allowed bit.
+ value of no_d3cold bit. Writing to this attribute is unsupported.
What: /sys/bus/pci/devices/.../sriov_totalvfs
Date: November 2012
diff --git a/drivers/pci/pci-acpi.c b/drivers/pci/pci-acpi.c
index 05b7357bd258..a05350a4e49c 100644
--- a/drivers/pci/pci-acpi.c
+++ b/drivers/pci/pci-acpi.c
@@ -911,7 +911,7 @@ pci_power_t acpi_pci_choose_state(struct pci_dev *pdev)
{
int acpi_state, d_max;
- if (pdev->no_d3cold || !pdev->d3cold_allowed)
+ if (pdev->no_d3cold)
d_max = ACPI_STATE_D3_HOT;
else
d_max = ACPI_STATE_D3_COLD;
diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
index 5e741a05cf2c..8c120f6778c6 100644
--- a/drivers/pci/pci-sysfs.c
+++ b/drivers/pci/pci-sysfs.c
@@ -519,31 +519,13 @@ static struct device_attribute dev_attr_bus_rescan = __ATTR(rescan, 0200, NULL,
bus_rescan_store);
#if defined(CONFIG_PM) && defined(CONFIG_ACPI)
-static ssize_t d3cold_allowed_store(struct device *dev,
- struct device_attribute *attr,
- const char *buf, size_t count)
-{
- struct pci_dev *pdev = to_pci_dev(dev);
- unsigned long val;
-
- if (kstrtoul(buf, 0, &val) < 0)
- return -EINVAL;
-
- pdev->d3cold_allowed = !!val;
- pci_bridge_d3_update(pdev);
-
- pm_runtime_resume(dev);
-
- return count;
-}
-
static ssize_t d3cold_allowed_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct pci_dev *pdev = to_pci_dev(dev);
- return sysfs_emit(buf, "%u\n", pdev->d3cold_allowed);
+ return sysfs_emit(buf, "%u\n", !pdev->no_d3cold);
}
-static DEVICE_ATTR_RW(d3cold_allowed);
+static DEVICE_ATTR_RO(d3cold_allowed);
#endif
#ifdef CONFIG_OF
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 59c01d68c6d5..8c5a6f68f63d 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -3067,7 +3067,7 @@ static int pci_dev_check_d3cold(struct pci_dev *dev, void *data)
bool *d3cold_ok = data;
if (/* The device needs to be allowed to go D3cold ... */
- dev->no_d3cold || !dev->d3cold_allowed ||
+ dev->no_d3cold ||
/* ... and if it is wakeup capable to do so from D3cold. */
(device_may_wakeup(&dev->dev) &&
@@ -3204,7 +3204,6 @@ void pci_pm_init(struct pci_dev *dev)
dev->d3hot_delay = PCI_PM_D3HOT_WAIT;
dev->d3cold_delay = PCI_PM_D3COLD_WAIT;
dev->bridge_d3 = pci_bridge_d3_possible(dev);
- dev->d3cold_allowed = true;
dev->d1_support = false;
dev->d2_support = false;
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 8c7c2c3c6c65..5f4ed71d31f5 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -376,7 +376,6 @@ struct pci_dev {
unsigned int no_d1d2:1; /* D1 and D2 are forbidden */
unsigned int no_d3cold:1; /* D3cold is forbidden */
unsigned int bridge_d3:1; /* Allow D3 for bridge */
- unsigned int d3cold_allowed:1; /* D3cold is allowed by user */
unsigned int mmio_always_on:1; /* Disallow turning off io/mem
decoding during BAR sizing */
unsigned int wakeup_prepared:1;
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] PCI: Make d3cold_allowed sysfs attribute read only
2023-10-02 18:10 [PATCH] PCI: Make d3cold_allowed sysfs attribute read only Mario Limonciello
@ 2023-10-03 9:44 ` Mika Westerberg
2023-10-03 16:30 ` Mario Limonciello
0 siblings, 1 reply; 4+ messages in thread
From: Mika Westerberg @ 2023-10-03 9:44 UTC (permalink / raw)
To: Mario Limonciello; +Cc: bhelgaas, lukas, linux-kernel, linux-pci
On Mon, Oct 02, 2023 at 01:10:25PM -0500, Mario Limonciello wrote:
> Before d3cold was stable userspace was allowed to influence the kernel's
> decision of whether to enable d3cold for a device by a sysfs file
> `d3cold_allowed`. This potentially allows userspace to break the suspend
> for the system.
>
> For debugging purposes `pci_port_pm=` can be used to control whether
> a PCI port will go into D3cold and runtime PM can be turned off by
> sysfs on PCI end points.
>
> Change the sysfs attribute to read-only and simplify the internal kernel
> logic to avoid needing to store the userspace request.
I wonder if this ends up breaking some userspace apps? Not objecting
though, just wanted to mention ;-)
One thing we could do is to taint the kernel or log a warning if
userspace touches this but allow it to do so.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] PCI: Make d3cold_allowed sysfs attribute read only
2023-10-03 9:44 ` Mika Westerberg
@ 2023-10-03 16:30 ` Mario Limonciello
2023-10-03 20:07 ` Lukas Wunner
0 siblings, 1 reply; 4+ messages in thread
From: Mario Limonciello @ 2023-10-03 16:30 UTC (permalink / raw)
To: Mika Westerberg; +Cc: bhelgaas, lukas, linux-kernel, linux-pci
On 10/3/2023 04:44, Mika Westerberg wrote:
> On Mon, Oct 02, 2023 at 01:10:25PM -0500, Mario Limonciello wrote:
>> Before d3cold was stable userspace was allowed to influence the kernel's
>> decision of whether to enable d3cold for a device by a sysfs file
>> `d3cold_allowed`. This potentially allows userspace to break the suspend
>> for the system.
>>
>> For debugging purposes `pci_port_pm=` can be used to control whether
>> a PCI port will go into D3cold and runtime PM can be turned off by
>> sysfs on PCI end points.
>>
>> Change the sysfs attribute to read-only and simplify the internal kernel
>> logic to avoid needing to store the userspace request.
>
> I wonder if this ends up breaking some userspace apps? Not objecting
> though, just wanted to mention ;-)
>
> One thing we could do is to taint the kernel or log a warning if
> userspace touches this but allow it to do so.
If we collectively decide it needs to stay RW for userspace compatbility
then I'll respin it to keep the store call but ignore whatever is
written, return -EINVAL and emit a pr_warn_once() that it's a no-op.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] PCI: Make d3cold_allowed sysfs attribute read only
2023-10-03 16:30 ` Mario Limonciello
@ 2023-10-03 20:07 ` Lukas Wunner
0 siblings, 0 replies; 4+ messages in thread
From: Lukas Wunner @ 2023-10-03 20:07 UTC (permalink / raw)
To: Mario Limonciello; +Cc: Mika Westerberg, bhelgaas, linux-kernel, linux-pci
On Tue, Oct 03, 2023 at 11:30:54AM -0500, Mario Limonciello wrote:
> On 10/3/2023 04:44, Mika Westerberg wrote:
> > On Mon, Oct 02, 2023 at 01:10:25PM -0500, Mario Limonciello wrote:
> > > Before d3cold was stable userspace was allowed to influence the kernel's
> > > decision of whether to enable d3cold for a device by a sysfs file
> > > `d3cold_allowed`. This potentially allows userspace to break the suspend
> > > for the system.
> > >
> > > For debugging purposes `pci_port_pm=` can be used to control whether
> > > a PCI port will go into D3cold and runtime PM can be turned off by
> > > sysfs on PCI end points.
> > >
> > > Change the sysfs attribute to read-only and simplify the internal kernel
> > > logic to avoid needing to store the userspace request.
> >
> > I wonder if this ends up breaking some userspace apps? Not objecting
> > though, just wanted to mention ;-)
> >
> > One thing we could do is to taint the kernel or log a warning if
> > userspace touches this but allow it to do so.
>
> If we collectively decide it needs to stay RW for userspace compatbility
> then I'll respin it to keep the store call but ignore whatever is written,
> return -EINVAL and emit a pr_warn_once() that it's a no-op.
I'd suggest to return 0 to avoid even the faintest ABI change whiff.
Just emit a warning once explaining that the feature is deprecated and
mark the attribute as such in ABI documentation.
Thanks,
Lukas
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-10-03 20:15 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-02 18:10 [PATCH] PCI: Make d3cold_allowed sysfs attribute read only Mario Limonciello
2023-10-03 9:44 ` Mika Westerberg
2023-10-03 16:30 ` Mario Limonciello
2023-10-03 20:07 ` Lukas Wunner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox