Skip to contentSkip to conversation

powerpc/pci: Fix broken INTx configuration via OF

PATCH Applied Alexey Kardashevskiy 7 participants 10 messages Feb 8, 2018 – Feb 9, 2018

Subsystems (2)

v1 of 3 Applied Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 powerpc/pci: Fix broken INTx configuration via OF

Commit 59f47eff03a0 ("powerpc/pci: Use of_irq_parse_and_map_pci() helper") correctly states that of_irq_parse_and_map_pci() does the same thing as of_irq_parse_pci() does as it simply calls
of_irq_parse_pci() and irq_create_of_mapping().

However of_irq_parse_and_map_pci() not only returns 0 for success and negative value for an error but also a positive virq value from irq_create_of_mapping() which the mentioned commit ignores and INTx config fails.

This fixes the of_irq_parse_and_map_pci() return value handling.

Fixes 59f47eff03a0 "powerpc/pci: Use of_irq_parse_and_map_pci() helper"

---

Found it on POWER9 + powernv system - almost all devices suddenly lost INTx support.

---
 arch/powerpc/kernel/pci-common.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/powerpc/kernel/pci-common.c +2 -1
index ae2ede4..acbb44f2 100644
@@ -370,7 +370,8 @@ static int pci_read_irq_line(struct pci_dev *pci_dev)
 	memset(&oirq, 0xff, sizeof(oirq));
 #endif
 	/* Try to get a mapping from the device-tree */
-	if (!of_irq_parse_and_map_pci(pci_dev, 0, 0)) {
+	virq = of_irq_parse_and_map_pci(pci_dev, 0, 0);
+	if (virq <= 0) {
 		u8 line, pin;
 
 		/* If that fails, lets fallback to what is in the config
Signature · 1 line
2.11.0
maintainer
#1 lore raw

[+cc linux-pci]

The original commit was merged via PCI, and I think it's a good idea to merge fixes to it the same way. I'll try to merge this in time for v4.16-rc1.

Quoted 39 lines · Alexey Kardashevskiy

Commit 59f47eff03a0 ("powerpc/pci: Use of_irq_parse_and_map_pci() helper") correctly states that of_irq_parse_and_map_pci() does the same thing as of_irq_parse_pci() does as it simply calls
of_irq_parse_pci() and irq_create_of_mapping().

However of_irq_parse_and_map_pci() not only returns 0 for success and negative value for an error but also a positive virq value from irq_create_of_mapping() which the mentioned commit ignores and INTx config fails.

This fixes the of_irq_parse_and_map_pci() return value handling.

Fixes 59f47eff03a0 "powerpc/pci: Use of_irq_parse_and_map_pci() helper"

---

Found it on POWER9 + powernv system - almost all devices suddenly lost INTx support.

---
 arch/powerpc/kernel/pci-common.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/powerpc/kernel/pci-common.c +2 -2
index ae2ede4..acbb44f2 100644
@@ -370,7 +370,8 @@ static int pci_read_irq_line(struct pci_dev *pci_dev)
        memset(&oirq, 0xff, sizeof(oirq));
 #endif
        /* Try to get a mapping from the device-tree */
-       if (!of_irq_parse_and_map_pci(pci_dev, 0, 0)) {
+       virq = of_irq_parse_and_map_pci(pci_dev, 0, 0);
+       if (virq <= 0) {
                u8 line, pin;
 
                /* If that fails, lets fallback to what is in the config
--

2.11.0

#2 lore raw
Quoted 29 lines · Bjorn Helgaas

[+cc linux-pci]

The original commit was merged via PCI, and I think it's a good idea to merge fixes to it the same way. I'll try to merge this in time for v4.16-rc1.

Quoted 22 lines · Alexey Kardashevskiy

Commit 59f47eff03a0 ("powerpc/pci: Use of_irq_parse_and_map_pci() helper") correctly states that of_irq_parse_and_map_pci() does the same thing as of_irq_parse_pci() does as it simply calls
of_irq_parse_pci() and irq_create_of_mapping().

However of_irq_parse_and_map_pci() not only returns 0 for success and negative value for an error but also a positive virq value from irq_create_of_mapping() which the mentioned commit ignores and INTx config fails.

This fixes the of_irq_parse_and_map_pci() return value handling.

Fixes 59f47eff03a0 "powerpc/pci: Use of_irq_parse_and_map_pci() helper"

---

Found it on POWER9 + powernv system - almost all devices suddenly lost INTx support.

---
 arch/powerpc/kernel/pci-common.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 11 lines

arch/powerpc/kernel/pci-common.c static int pci_read_irq_line(struct pci_dev *pci_dev) · line 374

Quoted 11 lines
arch/powerpc/kernel/pci-common.c +2 -1
index ae2ede4..acbb44f2 100644
@@ -370,7 +370,8 @@ static int pci_read_irq_line(struct pci_dev *pci_dev)
        memset(&oirq, 0xff, sizeof(oirq));
 #endif
        /* Try to get a mapping from the device-tree */
-       if (!of_irq_parse_and_map_pci(pci_dev, 0, 0)) {
+       virq = of_irq_parse_and_map_pci(pci_dev, 0, 0);
+       if (virq <= 0) {

I don't understand how this fix works. We used to check the result of of_irq_parse_and_map_pci() and entered the block if it was zero.

Now you enter the block if it is zero or less than zero, but:

static int pci_read_irq_line(...)

  {
    unsigned int virq = 0;     /* unnecessarily initialized, BTW */

    virq = of_irq_parse_and_map_pci(pci_dev, 0, 0);
    if (virq <= 0) {
      ...

virq is unsigned, so "virq < 0" can never be true. So how does this change anything?

Bjorn

#3 lore raw
Quoted 13 lines · Bjorn Helgaas

I don't understand how this fix works. We used to check the result of of_irq_parse_and_map_pci() and entered the block if it was zero.

Now you enter the block if it is zero or less than zero, but:

static int pci_read_irq_line(...)

  {
    unsigned int virq = 0;     /* unnecessarily initialized, BTW */

    virq = of_irq_parse_and_map_pci(pci_dev, 0, 0);
    if (virq <= 0) {
      ...
Quoted 2 lines

virq is unsigned, so "virq < 0" can never be true. So how does this change anything?

Yes it does:

So the unsigned thing is a second bug in the original patch that Alexey isn't fixing, we need to fix it too.

However, the actual bug Alexey is fixing is that we lost the actual value of virq. IE, without his fix, we test it for 0 but we don't actually return it if it's positive.

So he fixes the normal case but there's still a bug in the error case, we need to make virq signed.

Cheers,
Ben.

#4 lore raw
Quoted 17 lines · Benjamin Herrenschmidt
Quoted 13 lines · Bjorn Helgaas

I don't understand how this fix works. We used to check the result of of_irq_parse_and_map_pci() and entered the block if it was zero.

Now you enter the block if it is zero or less than zero, but:

static int pci_read_irq_line(...)

  {
    unsigned int virq = 0;     /* unnecessarily initialized, BTW */

    virq = of_irq_parse_and_map_pci(pci_dev, 0, 0);
    if (virq <= 0) {
      ...
Quoted 2 lines

virq is unsigned, so "virq < 0" can never be true. So how does this change anything?

Quoted 8 lines

Yes it does:

So the unsigned thing is a second bug in the original patch that Alexey isn't fixing, we need to fix it too.

However, the actual bug Alexey is fixing is that we lost the actual value of virq. IE, without his fix, we test it for 0 but we don't actually return it if it's positive.

Ah, I see, the bug is that we discarded the non-zero virq value when we actually need it. I'm going to wait for a new patch with a changelog that says that and doesn't test an unsigned value for < 0.

Quoted 2 lines

So he fixes the normal case but there's still a bug in the error case, we need to make virq signed.

I looked through the of_irq_parse_and_map_pci() path and I do not see a case where it can return a negative value. It either returns zero or one of these:

virq = irq_find_mapping(...)
virq = irq_create_mapping(...)

Both of these functions return unsigned values.

#5 lore raw
Quoted 34 lines · Bjorn Helgaas
Quoted 17 lines · Benjamin Herrenschmidt
Quoted 13 lines · Bjorn Helgaas

I don't understand how this fix works. We used to check the result of of_irq_parse_and_map_pci() and entered the block if it was zero.

Now you enter the block if it is zero or less than zero, but:

static int pci_read_irq_line(...)

  {
    unsigned int virq = 0;     /* unnecessarily initialized, BTW */

    virq = of_irq_parse_and_map_pci(pci_dev, 0, 0);
    if (virq <= 0) {
      ...
Quoted 2 lines

virq is unsigned, so "virq < 0" can never be true. So how does this change anything?

Quoted 8 lines

Yes it does:

So the unsigned thing is a second bug in the original patch that Alexey isn't fixing, we need to fix it too.

However, the actual bug Alexey is fixing is that we lost the actual value of virq. IE, without his fix, we test it for 0 but we don't actually return it if it's positive.

Ah, I see, the bug is that we discarded the non-zero virq value when we actually need it. I'm going to wait for a new patch with a changelog that says that and doesn't test an unsigned value for < 0.

Quoted 2 lines

So he fixes the normal case but there's still a bug in the error case, we need to make virq signed.

Quoted 8 lines

I looked through the of_irq_parse_and_map_pci() path and I do not see a case where it can return a negative value. It either returns zero or one of these:

virq = irq_find_mapping(...)
virq = irq_create_mapping(...)

Both of these functions return unsigned values.

Ok so the test is just wrong then. Aleey, can you respin ?

Cheers,
Ben.

Acked-by on v1 1/1
#6 lore raw
In reply to Alexey Kardashevskiy
Quoted 14 lines · Alexey Kardashevskiy

Commit 59f47eff03a0 ("powerpc/pci: Use of_irq_parse_and_map_pci() helper") correctly states that of_irq_parse_and_map_pci() does the same thing as of_irq_parse_pci() does as it simply calls
of_irq_parse_pci() and irq_create_of_mapping().

However of_irq_parse_and_map_pci() not only returns 0 for success and negative value for an error but also a positive virq value from irq_create_of_mapping() which the mentioned commit ignores and INTx config fails.

This fixes the of_irq_parse_and_map_pci() return value handling.

Fixes 59f47eff03a0 "powerpc/pci: Use of_irq_parse_and_map_pci() helper"
Quoted 7 lines

---

Found it on POWER9 + powernv system - almost all devices suddenly lost INTx support.

---
 arch/powerpc/kernel/pci-common.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Thanks.

#7 lore raw
In reply to Alexey Kardashevskiy
Quoted 10 lines · Alexey Kardashevskiy

Commit 59f47eff03a0 ("powerpc/pci: Use of_irq_parse_and_map_pci() helper") correctly states that of_irq_parse_and_map_pci() does the same thing as of_irq_parse_pci() does as it simply calls
of_irq_parse_pci() and irq_create_of_mapping().

However of_irq_parse_and_map_pci() not only returns 0 for success and negative value for an error but also a positive virq value from irq_create_of_mapping() which the mentioned commit ignores and INTx config fails.

Quoted 4 lines

This fixes the of_irq_parse_and_map_pci() return value handling.

Fixes 59f47eff03a0 "powerpc/pci: Use of_irq_parse_and_map_pci() helper"

Applied to powerpc fixes, thanks.

https://git.kernel.org/powerpc/c/560c0f978155282e36f33d21b2aeae

cheers

#8 lore raw
Quoted 11 lines · Michael Ellerman
Quoted 10 lines · Alexey Kardashevskiy

Commit 59f47eff03a0 ("powerpc/pci: Use of_irq_parse_and_map_pci() helper") correctly states that of_irq_parse_and_map_pci() does the same thing as of_irq_parse_pci() does as it simply calls
of_irq_parse_pci() and irq_create_of_mapping().

However of_irq_parse_and_map_pci() not only returns 0 for success and negative value for an error but also a positive virq value from irq_create_of_mapping() which the mentioned commit ignores and INTx config fails.

Quoted 8 lines
Quoted 4 lines

This fixes the of_irq_parse_and_map_pci() return value handling.

Fixes 59f47eff03a0 "powerpc/pci: Use of_irq_parse_and_map_pci() helper"

Applied to powerpc fixes, thanks.

https://git.kernel.org/powerpc/c/560c0f978155282e36f33d21b2aeae

there is a v2, this one is not 100% correct

Signature · 1 line
Alexey
#9 lore raw
Quoted 17 lines · Alexey Kardashevskiy
Quoted 16 lines · Michael Ellerman
Quoted 14 lines · Alexey Kardashevskiy

Commit 59f47eff03a0 ("powerpc/pci: Use of_irq_parse_and_map_pci() helper") correctly states that of_irq_parse_and_map_pci() does the same thing as of_irq_parse_pci() does as it simply calls
of_irq_parse_pci() and irq_create_of_mapping().

However of_irq_parse_and_map_pci() not only returns 0 for success and negative value for an error but also a positive virq value from irq_create_of_mapping() which the mentioned commit ignores and INTx config fails.

This fixes the of_irq_parse_and_map_pci() return value handling.

Fixes 59f47eff03a0 "powerpc/pci: Use of_irq_parse_and_map_pci() helper"
Quoted 6 lines
Quoted 3 lines

Applied to powerpc fixes, thanks.

https://git.kernel.org/powerpc/c/560c0f978155282e36f33d21b2aeae

there is a v2, this one is not 100% correct

Yeah I just saw, I'll back this out.

cheers