2017-08-17 02:26:15

by Ding Tianhong

[permalink] [raw]
Subject: [PATCH net] PCI: fix the return value for the pci_find_pcie_root_port()

The pci_find_pcie_root_port() would return NULL if the given
dev is already a Root Port, it looks like unfriendly to the
PCIe Root Port device, Thierry and Bjorn suggest to let this
function return the given dev under this circumstances.

Fixes: 0e405232871d6 ("PCI: fix oops when try to find Root Port for a PCI device")
Suggested-by: Thierry Reding <[email protected]>
Suggested-by: Bjorn Helgaas <[email protected]>
Signed-off-by: Thierry Reding <[email protected]>
Signed-off-by: Ding Tianhong <[email protected]>
---
drivers/pci/pci.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 7e2022f..352bb53 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -514,7 +514,7 @@ struct resource *pci_find_resource(struct pci_dev *dev, struct resource *res)
*/
struct pci_dev *pci_find_pcie_root_port(struct pci_dev *dev)
{
- struct pci_dev *bridge, *highest_pcie_bridge = NULL;
+ struct pci_dev *bridge, *highest_pcie_bridge = dev;

bridge = pci_upstream_bridge(dev);
while (bridge && pci_is_pcie(bridge)) {
--
1.8.3.1



2017-08-17 02:42:39

by David Miller

[permalink] [raw]
Subject: Re: [PATCH net] PCI: fix the return value for the pci_find_pcie_root_port()

From: Ding Tianhong <[email protected]>
Date: Thu, 17 Aug 2017 10:25:30 +0800

> The pci_find_pcie_root_port() would return NULL if the given
> dev is already a Root Port, it looks like unfriendly to the
> PCIe Root Port device, Thierry and Bjorn suggest to let this
> function return the given dev under this circumstances.
>
> Fixes: 0e405232871d6 ("PCI: fix oops when try to find Root Port for a PCI device")
> Suggested-by: Thierry Reding <[email protected]>
> Suggested-by: Bjorn Helgaas <[email protected]>
> Signed-off-by: Thierry Reding <[email protected]>
> Signed-off-by: Ding Tianhong <[email protected]>

Bjorn, please review and ACK so Linus doesn't rip my head off again
:-)

Thanks.

2017-08-17 10:52:04

by Thierry Reding

[permalink] [raw]
Subject: Re: [PATCH net] PCI: fix the return value for the pci_find_pcie_root_port()

On Thu, Aug 17, 2017 at 10:25:30AM +0800, Ding Tianhong wrote:
> The pci_find_pcie_root_port() would return NULL if the given
> dev is already a Root Port, it looks like unfriendly to the
> PCIe Root Port device, Thierry and Bjorn suggest to let this
> function return the given dev under this circumstances.
>
> Fixes: 0e405232871d6 ("PCI: fix oops when try to find Root Port for a PCI device")
> Suggested-by: Thierry Reding <[email protected]>
> Suggested-by: Bjorn Helgaas <[email protected]>
> Signed-off-by: Thierry Reding <[email protected]>
> Signed-off-by: Ding Tianhong <[email protected]>
> ---
> drivers/pci/pci.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
> index 7e2022f..352bb53 100644
> --- a/drivers/pci/pci.c
> +++ b/drivers/pci/pci.c
> @@ -514,7 +514,7 @@ struct resource *pci_find_resource(struct pci_dev *dev, struct resource *res)
> */
> struct pci_dev *pci_find_pcie_root_port(struct pci_dev *dev)
> {
> - struct pci_dev *bridge, *highest_pcie_bridge = NULL;
> + struct pci_dev *bridge, *highest_pcie_bridge = dev;
>
> bridge = pci_upstream_bridge(dev);
> while (bridge && pci_is_pcie(bridge)) {

I think this should actually be this change on top of a revert of commit
0e405232871d6 ("PCI: fix oops when try to find Root Port for a PCI
device"). After the above change, the previous fix will have a redundant
check because highest_pcie_bridge will never be NULL.

Let me send out that version to clarify what I mean.

Thierry


Attachments:
(No filename) (1.52 kB)
signature.asc (833.00 B)
Download all attachments

2017-08-17 11:06:20

by Thierry Reding

[permalink] [raw]
Subject: [PATCH] PCI: Allow PCI express root ports to find themselves

From: Thierry Reding <[email protected]>

If the pci_find_pcie_root_port() function is called on a root port
itself, return the root port rather than NULL.

This effectively reverts commit 0e405232871d6 ("PCI: fix oops when
try to find Root Port for a PCI device") which added an extra check
that would now be redundant.

Fixes: a99b646afa8a ("PCI: Disable PCIe Relaxed Ordering if unsupported")
Fixes: c56d4450eb68 ("PCI: Turn off Request Attributes to avoid Chelsio T5 Completion erratum")
Signed-off-by: Thierry Reding <[email protected]>
---
This applies on top of and was tested on next-20170817.

Michael, it'd be great if you could test this one again to clarify
whether or not the fix that's already in Linus' tree is still needed, or
whether it's indeed obsoleted by this patch.

drivers/pci/pci.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index b05c587e335a..dd56c1c05614 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -514,7 +514,7 @@ EXPORT_SYMBOL(pci_find_resource);
*/
struct pci_dev *pci_find_pcie_root_port(struct pci_dev *dev)
{
- struct pci_dev *bridge, *highest_pcie_bridge = NULL;
+ struct pci_dev *bridge, *highest_pcie_bridge = dev;

bridge = pci_upstream_bridge(dev);
while (bridge && pci_is_pcie(bridge)) {
@@ -522,11 +522,10 @@ struct pci_dev *pci_find_pcie_root_port(struct pci_dev *dev)
bridge = pci_upstream_bridge(bridge);
}

- if (highest_pcie_bridge &&
- pci_pcie_type(highest_pcie_bridge) == PCI_EXP_TYPE_ROOT_PORT)
- return highest_pcie_bridge;
+ if (pci_pcie_type(highest_pcie_bridge) != PCI_EXP_TYPE_ROOT_PORT)
+ return NULL;

- return NULL;
+ return highest_pcie_bridge;
}
EXPORT_SYMBOL(pci_find_pcie_root_port);

--
2.13.3

2017-08-17 12:41:40

by Ding Tianhong

[permalink] [raw]
Subject: Re: [PATCH net] PCI: fix the return value for the pci_find_pcie_root_port()



On 2017/8/17 18:51, Thierry Reding wrote:
> On Thu, Aug 17, 2017 at 10:25:30AM +0800, Ding Tianhong wrote:
>> The pci_find_pcie_root_port() would return NULL if the given
>> dev is already a Root Port, it looks like unfriendly to the
>> PCIe Root Port device, Thierry and Bjorn suggest to let this
>> function return the given dev under this circumstances.
>>
>> Fixes: 0e405232871d6 ("PCI: fix oops when try to find Root Port for a PCI device")
>> Suggested-by: Thierry Reding <[email protected]>
>> Suggested-by: Bjorn Helgaas <[email protected]>
>> Signed-off-by: Thierry Reding <[email protected]>
>> Signed-off-by: Ding Tianhong <[email protected]>
>> ---
>> drivers/pci/pci.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
>> index 7e2022f..352bb53 100644
>> --- a/drivers/pci/pci.c
>> +++ b/drivers/pci/pci.c
>> @@ -514,7 +514,7 @@ struct resource *pci_find_resource(struct pci_dev *dev, struct resource *res)
>> */
>> struct pci_dev *pci_find_pcie_root_port(struct pci_dev *dev)
>> {
>> - struct pci_dev *bridge, *highest_pcie_bridge = NULL;
>> + struct pci_dev *bridge, *highest_pcie_bridge = dev;
>>
>> bridge = pci_upstream_bridge(dev);
>> while (bridge && pci_is_pcie(bridge)) {
>
> I think this should actually be this change on top of a revert of commit
> 0e405232871d6 ("PCI: fix oops when try to find Root Port for a PCI
> device"). After the above change, the previous fix will have a redundant
> check because highest_pcie_bridge will never be NULL.
>
> Let me send out that version to clarify what I mean.
>

Hi Thierry:

The patch ("PCI: fix oops when try to find Root Port for a PCI device")
has been merge to the linus mainline tree before you found this deficiencies....

Regards
Tianhong

> Thierry
>

2017-08-17 13:30:20

by Thierry Reding

[permalink] [raw]
Subject: Re: [PATCH net] PCI: fix the return value for the pci_find_pcie_root_port()

On Thu, Aug 17, 2017 at 08:40:16PM +0800, Ding Tianhong wrote:
>
>
> On 2017/8/17 18:51, Thierry Reding wrote:
> > On Thu, Aug 17, 2017 at 10:25:30AM +0800, Ding Tianhong wrote:
> >> The pci_find_pcie_root_port() would return NULL if the given
> >> dev is already a Root Port, it looks like unfriendly to the
> >> PCIe Root Port device, Thierry and Bjorn suggest to let this
> >> function return the given dev under this circumstances.
> >>
> >> Fixes: 0e405232871d6 ("PCI: fix oops when try to find Root Port for a PCI device")
> >> Suggested-by: Thierry Reding <[email protected]>
> >> Suggested-by: Bjorn Helgaas <[email protected]>
> >> Signed-off-by: Thierry Reding <[email protected]>
> >> Signed-off-by: Ding Tianhong <[email protected]>
> >> ---
> >> drivers/pci/pci.c | 2 +-
> >> 1 file changed, 1 insertion(+), 1 deletion(-)
> >>
> >> diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
> >> index 7e2022f..352bb53 100644
> >> --- a/drivers/pci/pci.c
> >> +++ b/drivers/pci/pci.c
> >> @@ -514,7 +514,7 @@ struct resource *pci_find_resource(struct pci_dev *dev, struct resource *res)
> >> */
> >> struct pci_dev *pci_find_pcie_root_port(struct pci_dev *dev)
> >> {
> >> - struct pci_dev *bridge, *highest_pcie_bridge = NULL;
> >> + struct pci_dev *bridge, *highest_pcie_bridge = dev;
> >>
> >> bridge = pci_upstream_bridge(dev);
> >> while (bridge && pci_is_pcie(bridge)) {
> >
> > I think this should actually be this change on top of a revert of commit
> > 0e405232871d6 ("PCI: fix oops when try to find Root Port for a PCI
> > device"). After the above change, the previous fix will have a redundant
> > check because highest_pcie_bridge will never be NULL.
> >
> > Let me send out that version to clarify what I mean.
> >
>
> Hi Thierry:
>
> The patch ("PCI: fix oops when try to find Root Port for a PCI device")
> has been merge to the linus mainline tree before you found this deficiencies....

I understand that. I'm just saying that there's no point keeping that
change around because it no longer makes sense after we initialize the
highest_pcie_bridge variable to dev.

Thierry


Attachments:
(No filename) (2.09 kB)
signature.asc (833.00 B)
Download all attachments

2017-08-17 13:45:54

by Ding Tianhong

[permalink] [raw]
Subject: Re: [PATCH net] PCI: fix the return value for the pci_find_pcie_root_port()



On 2017/8/17 21:30, Thierry Reding wrote:
> On Thu, Aug 17, 2017 at 08:40:16PM +0800, Ding Tianhong wrote:
>>
>>
>> On 2017/8/17 18:51, Thierry Reding wrote:
>>> On Thu, Aug 17, 2017 at 10:25:30AM +0800, Ding Tianhong wrote:
>>>> The pci_find_pcie_root_port() would return NULL if the given
>>>> dev is already a Root Port, it looks like unfriendly to the
>>>> PCIe Root Port device, Thierry and Bjorn suggest to let this
>>>> function return the given dev under this circumstances.
>>>>
>>>> Fixes: 0e405232871d6 ("PCI: fix oops when try to find Root Port for a PCI device")
>>>> Suggested-by: Thierry Reding <[email protected]>
>>>> Suggested-by: Bjorn Helgaas <[email protected]>
>>>> Signed-off-by: Thierry Reding <[email protected]>
>>>> Signed-off-by: Ding Tianhong <[email protected]>
>>>> ---
>>>> drivers/pci/pci.c | 2 +-
>>>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>>>
>>>> diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
>>>> index 7e2022f..352bb53 100644
>>>> --- a/drivers/pci/pci.c
>>>> +++ b/drivers/pci/pci.c
>>>> @@ -514,7 +514,7 @@ struct resource *pci_find_resource(struct pci_dev *dev, struct resource *res)
>>>> */
>>>> struct pci_dev *pci_find_pcie_root_port(struct pci_dev *dev)
>>>> {
>>>> - struct pci_dev *bridge, *highest_pcie_bridge = NULL;
>>>> + struct pci_dev *bridge, *highest_pcie_bridge = dev;
>>>>
>>>> bridge = pci_upstream_bridge(dev);
>>>> while (bridge && pci_is_pcie(bridge)) {
>>>
>>> I think this should actually be this change on top of a revert of commit
>>> 0e405232871d6 ("PCI: fix oops when try to find Root Port for a PCI
>>> device"). After the above change, the previous fix will have a redundant
>>> check because highest_pcie_bridge will never be NULL.
>>>
>>> Let me send out that version to clarify what I mean.
>>>
>>
>> Hi Thierry:
>>
>> The patch ("PCI: fix oops when try to find Root Port for a PCI device")
>> has been merge to the linus mainline tree before you found this deficiencies....
>
> I understand that. I'm just saying that there's no point keeping that
> change around because it no longer makes sense after we initialize the
> highest_pcie_bridge variable to dev.
>

Ok, NO problem.:)

> Thierry
>

2017-08-17 16:58:51

by Bjorn Helgaas

[permalink] [raw]
Subject: Re: [PATCH] PCI: Allow PCI express root ports to find themselves

On Thu, Aug 17, 2017 at 01:06:14PM +0200, Thierry Reding wrote:
> From: Thierry Reding <[email protected]>
>
> If the pci_find_pcie_root_port() function is called on a root port
> itself, return the root port rather than NULL.
>
> This effectively reverts commit 0e405232871d6 ("PCI: fix oops when
> try to find Root Port for a PCI device") which added an extra check
> that would now be redundant.
>
> Fixes: a99b646afa8a ("PCI: Disable PCIe Relaxed Ordering if unsupported")
> Fixes: c56d4450eb68 ("PCI: Turn off Request Attributes to avoid Chelsio T5 Completion erratum")
> Signed-off-by: Thierry Reding <[email protected]>

Acked-by: Bjorn Helgaas <[email protected]>

I *think* this should work for everybody, but I can't test it personally.

> ---
> This applies on top of and was tested on next-20170817.
>
> Michael, it'd be great if you could test this one again to clarify
> whether or not the fix that's already in Linus' tree is still needed, or
> whether it's indeed obsoleted by this patch.
>
> drivers/pci/pci.c | 9 ++++-----
> 1 file changed, 4 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
> index b05c587e335a..dd56c1c05614 100644
> --- a/drivers/pci/pci.c
> +++ b/drivers/pci/pci.c
> @@ -514,7 +514,7 @@ EXPORT_SYMBOL(pci_find_resource);
> */
> struct pci_dev *pci_find_pcie_root_port(struct pci_dev *dev)
> {
> - struct pci_dev *bridge, *highest_pcie_bridge = NULL;
> + struct pci_dev *bridge, *highest_pcie_bridge = dev;
>
> bridge = pci_upstream_bridge(dev);
> while (bridge && pci_is_pcie(bridge)) {
> @@ -522,11 +522,10 @@ struct pci_dev *pci_find_pcie_root_port(struct pci_dev *dev)
> bridge = pci_upstream_bridge(bridge);
> }
>
> - if (highest_pcie_bridge &&
> - pci_pcie_type(highest_pcie_bridge) == PCI_EXP_TYPE_ROOT_PORT)
> - return highest_pcie_bridge;
> + if (pci_pcie_type(highest_pcie_bridge) != PCI_EXP_TYPE_ROOT_PORT)
> + return NULL;
>
> - return NULL;
> + return highest_pcie_bridge;
> }
> EXPORT_SYMBOL(pci_find_pcie_root_port);
>
> --
> 2.13.3
>
>
> _______________________________________________
> linux-arm-kernel mailing list
> [email protected]
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

2017-08-18 01:29:32

by Shawn Lin

[permalink] [raw]
Subject: Re: [PATCH] PCI: Allow PCI express root ports to find themselves

Hi

On 2017/8/17 19:06, Thierry Reding wrote:
> From: Thierry Reding <[email protected]>
>
> If the pci_find_pcie_root_port() function is called on a root port
> itself, return the root port rather than NULL.
>
> This effectively reverts commit 0e405232871d6 ("PCI: fix oops when
> try to find Root Port for a PCI device") which added an extra check
> that would now be redundant.
>
> Fixes: a99b646afa8a ("PCI: Disable PCIe Relaxed Ordering if unsupported")
> Fixes: c56d4450eb68 ("PCI: Turn off Request Attributes to avoid Chelsio T5 Completion erratum")
> Signed-off-by: Thierry Reding <[email protected]>

Tested-by: Shawn Lin <[email protected]>

> ---
> This applies on top of and was tested on next-20170817.
>
> Michael, it'd be great if you could test this one again to clarify
> whether or not the fix that's already in Linus' tree is still needed, or
> whether it's indeed obsoleted by this patch.
>
> drivers/pci/pci.c | 9 ++++-----
> 1 file changed, 4 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
> index b05c587e335a..dd56c1c05614 100644
> --- a/drivers/pci/pci.c
> +++ b/drivers/pci/pci.c
> @@ -514,7 +514,7 @@ EXPORT_SYMBOL(pci_find_resource);
> */
> struct pci_dev *pci_find_pcie_root_port(struct pci_dev *dev)
> {
> - struct pci_dev *bridge, *highest_pcie_bridge = NULL;
> + struct pci_dev *bridge, *highest_pcie_bridge = dev;
>
> bridge = pci_upstream_bridge(dev);
> while (bridge && pci_is_pcie(bridge)) {
> @@ -522,11 +522,10 @@ struct pci_dev *pci_find_pcie_root_port(struct pci_dev *dev)
> bridge = pci_upstream_bridge(bridge);
> }
>
> - if (highest_pcie_bridge &&
> - pci_pcie_type(highest_pcie_bridge) == PCI_EXP_TYPE_ROOT_PORT)
> - return highest_pcie_bridge;
> + if (pci_pcie_type(highest_pcie_bridge) != PCI_EXP_TYPE_ROOT_PORT)
> + return NULL;
>
> - return NULL;
> + return highest_pcie_bridge;
> }
> EXPORT_SYMBOL(pci_find_pcie_root_port);
>
>

2017-08-18 04:32:43

by Michael Ellerman

[permalink] [raw]
Subject: Re: [PATCH] PCI: Allow PCI express root ports to find themselves

Thierry Reding <[email protected]> writes:

> From: Thierry Reding <[email protected]>
>
> If the pci_find_pcie_root_port() function is called on a root port
> itself, return the root port rather than NULL.
>
> This effectively reverts commit 0e405232871d6 ("PCI: fix oops when
> try to find Root Port for a PCI device") which added an extra check
> that would now be redundant.
>
> Fixes: a99b646afa8a ("PCI: Disable PCIe Relaxed Ordering if unsupported")
> Fixes: c56d4450eb68 ("PCI: Turn off Request Attributes to avoid Chelsio T5 Completion erratum")
> Signed-off-by: Thierry Reding <[email protected]>
> ---
> This applies on top of and was tested on next-20170817.
>
> Michael, it'd be great if you could test this one again to clarify
> whether or not the fix that's already in Linus' tree is still needed, or
> whether it's indeed obsoleted by this patch.

This works fine for me, applied on top of Linus' tree (d33a2a914319).

cheers

2017-08-18 23:14:56

by David Miller

[permalink] [raw]
Subject: Re: [PATCH] PCI: Allow PCI express root ports to find themselves

From: Thierry Reding <[email protected]>
Date: Thu, 17 Aug 2017 13:06:14 +0200

> From: Thierry Reding <[email protected]>
>
> If the pci_find_pcie_root_port() function is called on a root port
> itself, return the root port rather than NULL.
>
> This effectively reverts commit 0e405232871d6 ("PCI: fix oops when
> try to find Root Port for a PCI device") which added an extra check
> that would now be redundant.
>
> Fixes: a99b646afa8a ("PCI: Disable PCIe Relaxed Ordering if unsupported")
> Fixes: c56d4450eb68 ("PCI: Turn off Request Attributes to avoid Chelsio T5 Completion erratum")
> Signed-off-by: Thierry Reding <[email protected]>
> ---
> This applies on top of and was tested on next-20170817.
>
> Michael, it'd be great if you could test this one again to clarify
> whether or not the fix that's already in Linus' tree is still needed, or
> whether it's indeed obsoleted by this patch.

Applied, thanks everyone.