* [PATCH] PCI: Make pcie_find_root_port() work for PCIe root ports as well
@ 2020-06-22 16:12 Mika Westerberg
2020-06-30 22:01 ` Bjorn Helgaas
0 siblings, 1 reply; 6+ messages in thread
From: Mika Westerberg @ 2020-06-22 16:12 UTC (permalink / raw)
To: Bjorn Helgaas; +Cc: Kalle Valo, Yicong Yang, Mika Westerberg, linux-pci
Commit 6ae72bfa656e ("PCI: Unify pcie_find_root_port() and
pci_find_pcie_root_port()") unified the root port finding functionality
into a single function but missed the fact that the passed in device may
already be a root port. This causes the kernel to block power management
of PCIe hierarchies in recent systems because ->bridge_d3 started to
return false for such ports after the commit in question.
Fixes: 6ae72bfa656e ("PCI: Unify pcie_find_root_port() and pci_find_pcie_root_port()")
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Cc: stable@vger.kernel.org
---
include/linux/pci.h | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/include/linux/pci.h b/include/linux/pci.h
index c79d83304e52..c17c24f5eeed 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -2169,8 +2169,13 @@ static inline int pci_pcie_type(const struct pci_dev *dev)
*/
static inline struct pci_dev *pcie_find_root_port(struct pci_dev *dev)
{
- struct pci_dev *bridge = pci_upstream_bridge(dev);
+ struct pci_dev *bridge;
+ /* If dev is already root port */
+ if (pci_pcie_type(dev) == PCI_EXP_TYPE_ROOT_PORT)
+ return dev;
+
+ bridge = pci_upstream_bridge(dev);
while (bridge) {
if (pci_pcie_type(bridge) == PCI_EXP_TYPE_ROOT_PORT)
return bridge;
--
2.27.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] PCI: Make pcie_find_root_port() work for PCIe root ports as well
2020-06-22 16:12 [PATCH] PCI: Make pcie_find_root_port() work for PCIe root ports as well Mika Westerberg
@ 2020-06-30 22:01 ` Bjorn Helgaas
2020-07-01 1:53 ` Yicong Yang
2020-07-01 10:14 ` Mika Westerberg
0 siblings, 2 replies; 6+ messages in thread
From: Bjorn Helgaas @ 2020-06-30 22:01 UTC (permalink / raw)
To: Mika Westerberg; +Cc: Bjorn Helgaas, Kalle Valo, Yicong Yang, linux-pci
On Mon, Jun 22, 2020 at 07:12:48PM +0300, Mika Westerberg wrote:
> Commit 6ae72bfa656e ("PCI: Unify pcie_find_root_port() and
> pci_find_pcie_root_port()") unified the root port finding functionality
> into a single function but missed the fact that the passed in device may
> already be a root port. This causes the kernel to block power management
> of PCIe hierarchies in recent systems because ->bridge_d3 started to
> return false for such ports after the commit in question.
>
> Fixes: 6ae72bfa656e ("PCI: Unify pcie_find_root_port() and pci_find_pcie_root_port()")
> Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
> Cc: stable@vger.kernel.org
> ---
> include/linux/pci.h | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/include/linux/pci.h b/include/linux/pci.h
> index c79d83304e52..c17c24f5eeed 100644
> --- a/include/linux/pci.h
> +++ b/include/linux/pci.h
> @@ -2169,8 +2169,13 @@ static inline int pci_pcie_type(const struct pci_dev *dev)
> */
> static inline struct pci_dev *pcie_find_root_port(struct pci_dev *dev)
> {
> - struct pci_dev *bridge = pci_upstream_bridge(dev);
> + struct pci_dev *bridge;
>
> + /* If dev is already root port */
> + if (pci_pcie_type(dev) == PCI_EXP_TYPE_ROOT_PORT)
> + return dev;
> +
> + bridge = pci_upstream_bridge(dev);
> while (bridge) {
> if (pci_pcie_type(bridge) == PCI_EXP_TYPE_ROOT_PORT)
> return bridge;
I applied the patch below, which is slightly simplified but I think
still equivalent, to for-linus for v5.8. Let me know if it's not.
I dropped the stable tag because 6ae72bfa656e was merged for v5.8-rc1,
and I assume v5.7 works correctly so it doesn't need any change.
commit 5396956cc7c6 ("PCI: Make pcie_find_root_port() work for Root Ports")
Author: Mika Westerberg <mika.westerberg@linux.intel.com>
Date: Mon Jun 22 19:12:48 2020 +0300
PCI: Make pcie_find_root_port() work for Root Ports
Commit 6ae72bfa656e ("PCI: Unify pcie_find_root_port() and
pci_find_pcie_root_port()") broke acpi_pci_bridge_d3() because calling
pcie_find_root_port() on a Root Port returned NULL when it should return
the Root Port, which in turn broke power management of PCIe hierarchies.
Rework pcie_find_root_port() so it returns its argument when it is already
a Root Port.
[bhelgaas: test device only once, test for PCIe]
Fixes: 6ae72bfa656e ("PCI: Unify pcie_find_root_port() and pci_find_pcie_root_port()")
Link: https://lore.kernel.org/r/20200622161248.51099-1-mika.westerberg@linux.intel.com
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
diff --git a/include/linux/pci.h b/include/linux/pci.h
index c79d83304e52..34c1c4f45288 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -2169,12 +2169,11 @@ static inline int pci_pcie_type(const struct pci_dev *dev)
*/
static inline struct pci_dev *pcie_find_root_port(struct pci_dev *dev)
{
- struct pci_dev *bridge = pci_upstream_bridge(dev);
-
- while (bridge) {
- if (pci_pcie_type(bridge) == PCI_EXP_TYPE_ROOT_PORT)
- return bridge;
- bridge = pci_upstream_bridge(bridge);
+ while (dev) {
+ if (pci_is_pcie(dev) &&
+ pci_pcie_type(dev) == PCI_EXP_TYPE_ROOT_PORT)
+ return dev;
+ dev = pci_upstream_bridge(dev);
}
return NULL;
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] PCI: Make pcie_find_root_port() work for PCIe root ports as well
2020-06-30 22:01 ` Bjorn Helgaas
@ 2020-07-01 1:53 ` Yicong Yang
2020-07-01 10:15 ` Mika Westerberg
2020-07-01 10:14 ` Mika Westerberg
1 sibling, 1 reply; 6+ messages in thread
From: Yicong Yang @ 2020-07-01 1:53 UTC (permalink / raw)
To: Bjorn Helgaas, Mika Westerberg; +Cc: Bjorn Helgaas, Kalle Valo, linux-pci
Hi Bjorn,
On 2020/7/1 6:01, Bjorn Helgaas wrote:
> On Mon, Jun 22, 2020 at 07:12:48PM +0300, Mika Westerberg wrote:
>> Commit 6ae72bfa656e ("PCI: Unify pcie_find_root_port() and
>> pci_find_pcie_root_port()") unified the root port finding functionality
>> into a single function but missed the fact that the passed in device may
>> already be a root port. This causes the kernel to block power management
>> of PCIe hierarchies in recent systems because ->bridge_d3 started to
>> return false for such ports after the commit in question.
>>
>> Fixes: 6ae72bfa656e ("PCI: Unify pcie_find_root_port() and pci_find_pcie_root_port()")
>> Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
>> Cc: stable@vger.kernel.org
>> ---
>> include/linux/pci.h | 7 ++++++-
>> 1 file changed, 6 insertions(+), 1 deletion(-)
>>
>> diff --git a/include/linux/pci.h b/include/linux/pci.h
>> index c79d83304e52..c17c24f5eeed 100644
>> --- a/include/linux/pci.h
>> +++ b/include/linux/pci.h
>> @@ -2169,8 +2169,13 @@ static inline int pci_pcie_type(const struct pci_dev *dev)
>> */
>> static inline struct pci_dev *pcie_find_root_port(struct pci_dev *dev)
>> {
>> - struct pci_dev *bridge = pci_upstream_bridge(dev);
>> + struct pci_dev *bridge;
>>
>> + /* If dev is already root port */
>> + if (pci_pcie_type(dev) == PCI_EXP_TYPE_ROOT_PORT)
>> + return dev;
>> +
>> + bridge = pci_upstream_bridge(dev);
>> while (bridge) {
>> if (pci_pcie_type(bridge) == PCI_EXP_TYPE_ROOT_PORT)
>> return bridge;
> I applied the patch below, which is slightly simplified but I think
> still equivalent, to for-linus for v5.8. Let me know if it's not.
>
> I dropped the stable tag because 6ae72bfa656e was merged for v5.8-rc1,
> and I assume v5.7 works correctly so it doesn't need any change.
>
>
> commit 5396956cc7c6 ("PCI: Make pcie_find_root_port() work for Root Ports")
> Author: Mika Westerberg <mika.westerberg@linux.intel.com>
> Date: Mon Jun 22 19:12:48 2020 +0300
>
> PCI: Make pcie_find_root_port() work for Root Ports
>
> Commit 6ae72bfa656e ("PCI: Unify pcie_find_root_port() and
> pci_find_pcie_root_port()") broke acpi_pci_bridge_d3() because calling
> pcie_find_root_port() on a Root Port returned NULL when it should return
> the Root Port, which in turn broke power management of PCIe hierarchies.
>
> Rework pcie_find_root_port() so it returns its argument when it is already
> a Root Port.
>
> [bhelgaas: test device only once, test for PCIe]
> Fixes: 6ae72bfa656e ("PCI: Unify pcie_find_root_port() and pci_find_pcie_root_port()")
> Link: https://lore.kernel.org/r/20200622161248.51099-1-mika.westerberg@linux.intel.com
> Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
>
> diff --git a/include/linux/pci.h b/include/linux/pci.h
> index c79d83304e52..34c1c4f45288 100644
> --- a/include/linux/pci.h
> +++ b/include/linux/pci.h
> @@ -2169,12 +2169,11 @@ static inline int pci_pcie_type(const struct pci_dev *dev)
> */
> static inline struct pci_dev *pcie_find_root_port(struct pci_dev *dev)
> {
> - struct pci_dev *bridge = pci_upstream_bridge(dev);
> -
> - while (bridge) {
> - if (pci_pcie_type(bridge) == PCI_EXP_TYPE_ROOT_PORT)
> - return bridge;
> - bridge = pci_upstream_bridge(bridge);
> + while (dev) {
> + if (pci_is_pcie(dev) &&
> + pci_pcie_type(dev) == PCI_EXP_TYPE_ROOT_PORT)
> + return dev;
> + dev = pci_upstream_bridge(dev);
> }
>
We may have some problems here, as after pcie_find_root_port() called, *dev will
be either root port or NULL but users may want it unchanged. One such usage is
in acpi_pci_bridge_d3(), drivers/pci/pci-acpi.c, *dev is used as origin
after called this.
So we should use a temporary point to *dev rather than directly modify it.
Thanks,
Yicong
> return NULL;
> .
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] PCI: Make pcie_find_root_port() work for PCIe root ports as well
2020-06-30 22:01 ` Bjorn Helgaas
2020-07-01 1:53 ` Yicong Yang
@ 2020-07-01 10:14 ` Mika Westerberg
1 sibling, 0 replies; 6+ messages in thread
From: Mika Westerberg @ 2020-07-01 10:14 UTC (permalink / raw)
To: Bjorn Helgaas; +Cc: Bjorn Helgaas, Kalle Valo, Yicong Yang, linux-pci
On Tue, Jun 30, 2020 at 05:01:07PM -0500, Bjorn Helgaas wrote:
> On Mon, Jun 22, 2020 at 07:12:48PM +0300, Mika Westerberg wrote:
> > Commit 6ae72bfa656e ("PCI: Unify pcie_find_root_port() and
> > pci_find_pcie_root_port()") unified the root port finding functionality
> > into a single function but missed the fact that the passed in device may
> > already be a root port. This causes the kernel to block power management
> > of PCIe hierarchies in recent systems because ->bridge_d3 started to
> > return false for such ports after the commit in question.
> >
> > Fixes: 6ae72bfa656e ("PCI: Unify pcie_find_root_port() and pci_find_pcie_root_port()")
> > Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
> > Cc: stable@vger.kernel.org
> > ---
> > include/linux/pci.h | 7 ++++++-
> > 1 file changed, 6 insertions(+), 1 deletion(-)
> >
> > diff --git a/include/linux/pci.h b/include/linux/pci.h
> > index c79d83304e52..c17c24f5eeed 100644
> > --- a/include/linux/pci.h
> > +++ b/include/linux/pci.h
> > @@ -2169,8 +2169,13 @@ static inline int pci_pcie_type(const struct pci_dev *dev)
> > */
> > static inline struct pci_dev *pcie_find_root_port(struct pci_dev *dev)
> > {
> > - struct pci_dev *bridge = pci_upstream_bridge(dev);
> > + struct pci_dev *bridge;
> >
> > + /* If dev is already root port */
> > + if (pci_pcie_type(dev) == PCI_EXP_TYPE_ROOT_PORT)
> > + return dev;
> > +
> > + bridge = pci_upstream_bridge(dev);
> > while (bridge) {
> > if (pci_pcie_type(bridge) == PCI_EXP_TYPE_ROOT_PORT)
> > return bridge;
>
> I applied the patch below, which is slightly simplified but I think
> still equivalent, to for-linus for v5.8. Let me know if it's not.
Thanks I just tested and it also works fine.
> I dropped the stable tag because 6ae72bfa656e was merged for v5.8-rc1,
> and I assume v5.7 works correctly so it doesn't need any change.
Right, makes sense.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] PCI: Make pcie_find_root_port() work for PCIe root ports as well
2020-07-01 1:53 ` Yicong Yang
@ 2020-07-01 10:15 ` Mika Westerberg
2020-07-01 12:47 ` Yicong Yang
0 siblings, 1 reply; 6+ messages in thread
From: Mika Westerberg @ 2020-07-01 10:15 UTC (permalink / raw)
To: Yicong Yang; +Cc: Bjorn Helgaas, Bjorn Helgaas, Kalle Valo, linux-pci
On Wed, Jul 01, 2020 at 09:53:51AM +0800, Yicong Yang wrote:
> > static inline struct pci_dev *pcie_find_root_port(struct pci_dev *dev)
> > {
> > - struct pci_dev *bridge = pci_upstream_bridge(dev);
> > -
> > - while (bridge) {
> > - if (pci_pcie_type(bridge) == PCI_EXP_TYPE_ROOT_PORT)
> > - return bridge;
> > - bridge = pci_upstream_bridge(bridge);
> > + while (dev) {
> > + if (pci_is_pcie(dev) &&
> > + pci_pcie_type(dev) == PCI_EXP_TYPE_ROOT_PORT)
> > + return dev;
> > + dev = pci_upstream_bridge(dev);
> > }
> >
>
> We may have some problems here, as after pcie_find_root_port() called, *dev will
> be either root port or NULL but users may want it unchanged. One such usage is
> in acpi_pci_bridge_d3(), drivers/pci/pci-acpi.c, *dev is used as origin
> after called this.
>
> So we should use a temporary point to *dev rather than directly modify it.
dev is already a copy of what is passed by the caller so it does not
matter if it gets changed here. You would need to pass it through struct
pci_dev **dev in order to modify the passed pointer.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] PCI: Make pcie_find_root_port() work for PCIe root ports as well
2020-07-01 10:15 ` Mika Westerberg
@ 2020-07-01 12:47 ` Yicong Yang
0 siblings, 0 replies; 6+ messages in thread
From: Yicong Yang @ 2020-07-01 12:47 UTC (permalink / raw)
To: Mika Westerberg; +Cc: Bjorn Helgaas, Bjorn Helgaas, Kalle Valo, linux-pci
On 2020/7/1 18:15, Mika Westerberg wrote:
> On Wed, Jul 01, 2020 at 09:53:51AM +0800, Yicong Yang wrote:
>>> static inline struct pci_dev *pcie_find_root_port(struct pci_dev *dev)
>>> {
>>> - struct pci_dev *bridge = pci_upstream_bridge(dev);
>>> -
>>> - while (bridge) {
>>> - if (pci_pcie_type(bridge) == PCI_EXP_TYPE_ROOT_PORT)
>>> - return bridge;
>>> - bridge = pci_upstream_bridge(bridge);
>>> + while (dev) {
>>> + if (pci_is_pcie(dev) &&
>>> + pci_pcie_type(dev) == PCI_EXP_TYPE_ROOT_PORT)
>>> + return dev;
>>> + dev = pci_upstream_bridge(dev);
>>> }
>>>
>> We may have some problems here, as after pcie_find_root_port() called, *dev will
>> be either root port or NULL but users may want it unchanged. One such usage is
>> in acpi_pci_bridge_d3(), drivers/pci/pci-acpi.c, *dev is used as origin
>> after called this.
>>
>> So we should use a temporary point to *dev rather than directly modify it.
> dev is already a copy of what is passed by the caller so it does not
> matter if it gets changed here. You would need to pass it through struct
> pci_dev **dev in order to modify the passed pointer.
Ah...I must be fuzzy in mind then. Thanks.
> .
>
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2020-07-01 12:47 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-22 16:12 [PATCH] PCI: Make pcie_find_root_port() work for PCIe root ports as well Mika Westerberg
2020-06-30 22:01 ` Bjorn Helgaas
2020-07-01 1:53 ` Yicong Yang
2020-07-01 10:15 ` Mika Westerberg
2020-07-01 12:47 ` Yicong Yang
2020-07-01 10:14 ` Mika Westerberg
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.