Skip to contentSkip to conversation

misc/GenWQE: fix pci_enable_msi usage

PATCH In review Sebastian Ott 4 participants 8 messages Jul 9, 2014 – Jul 21, 2014

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 misc/GenWQE: fix pci_enable_msi usage

GenWQE used to call pci_enable_msi_block to allocate a desired number of MSI's. If that was not possible pci_enable_msi_block returned with a smaller number which might be possible to allocate. GenWQE then called pci_enable_msi_block with that number.

Since commit a30d0108b
"GenWQE: Use pci_enable_msi_exact() instead of pci_enable_msi_block()" pci_enable_msi_exact is used which fails if the desired number of MSI's was not possible to allocate. Change GenWQE to use pci_enable_msi_range to restore the old behavior.

---
 drivers/misc/genwqe/card_ddcb.c  |  4 +---
 drivers/misc/genwqe/card_utils.c | 10 ++++++----
 2 files changed, 7 insertions(+), 7 deletions(-)
drivers/misc/genwqe/card_ddcb.c +1 -3
index c8046db..f66d43d 100644
@@ -1237,9 +1237,7 @@ int genwqe_setup_service_layer(struct genwqe_dev *cd)
 	}
 
 	rc = genwqe_set_interrupt_capability(cd, GENWQE_MSI_IRQS);
-	if (rc > 0)
-		rc = genwqe_set_interrupt_capability(cd, rc);
-	if (rc != 0) {
+	if (rc) {
 		rc = -ENODEV;
 		goto stop_kthread;
 	}
drivers/misc/genwqe/card_utils.c +6 -4
index 62cc6bb..6abc437 100644
@@ -718,10 +718,12 @@ int genwqe_set_interrupt_capability(struct genwqe_dev *cd, int count)
 	int rc;
 	struct pci_dev *pci_dev = cd->pci_dev;
 
-	rc = pci_enable_msi_exact(pci_dev, count);
-	if (rc == 0)
-		cd->flags |= GENWQE_FLAG_MSI_ENABLED;
-	return rc;
+	rc = pci_enable_msi_range(pci_dev, 1, count);
+	if (rc < 0)
+		return rc;
+
+	cd->flags |= GENWQE_FLAG_MSI_ENABLED;
+	return 0;
 }
 
 /**
Signature · 1 line
1.9.3
Reviewed-by on v1 1/1
#1 lore raw
Quoted 56 lines · Sebastian Ott

GenWQE used to call pci_enable_msi_block to allocate a desired number of MSI's. If that was not possible pci_enable_msi_block returned with a smaller number which might be possible to allocate. GenWQE then called pci_enable_msi_block with that number.

Since commit a30d0108b
"GenWQE: Use pci_enable_msi_exact() instead of pci_enable_msi_block()" pci_enable_msi_exact is used which fails if the desired number of MSI's was not possible to allocate. Change GenWQE to use pci_enable_msi_range to restore the old behavior.

---
 drivers/misc/genwqe/card_ddcb.c  |  4 +---
 drivers/misc/genwqe/card_utils.c | 10 ++++++----
 2 files changed, 7 insertions(+), 7 deletions(-)
drivers/misc/genwqe/card_ddcb.c +1 -3
index c8046db..f66d43d 100644
@@ -1237,9 +1237,7 @@ int genwqe_setup_service_layer(struct genwqe_dev *cd)
 	}
 
 	rc = genwqe_set_interrupt_capability(cd, GENWQE_MSI_IRQS);
-	if (rc > 0)
-		rc = genwqe_set_interrupt_capability(cd, rc);
-	if (rc != 0) {
+	if (rc) {
 		rc = -ENODEV;
 		goto stop_kthread;
 	}
drivers/misc/genwqe/card_utils.c +6 -4
index 62cc6bb..6abc437 100644
@@ -718,10 +718,12 @@ int genwqe_set_interrupt_capability(struct genwqe_dev *cd, int count)
 	int rc;
 	struct pci_dev *pci_dev = cd->pci_dev;
 
-	rc = pci_enable_msi_exact(pci_dev, count);
-	if (rc == 0)
-		cd->flags |= GENWQE_FLAG_MSI_ENABLED;
-	return rc;
+	rc = pci_enable_msi_range(pci_dev, 1, count);
+	if (rc < 0)
+		return rc;
+
+	cd->flags |= GENWQE_FLAG_MSI_ENABLED;
+	return 0;
 }
 
 /**
Signature · 1 line
1.9.3

I am curious though why would you need convert error code to -ENODEV here (and throughout the code in general)?

Thanks!

Signature · 3 lines
Regards,
Alexander Gordeev
[email protected]
#2 lore raw
Quoted 60 lines · Alexander Gordeev
Quoted 56 lines · Sebastian Ott

GenWQE used to call pci_enable_msi_block to allocate a desired number of MSI's. If that was not possible pci_enable_msi_block returned with a smaller number which might be possible to allocate. GenWQE then called pci_enable_msi_block with that number.

Since commit a30d0108b
"GenWQE: Use pci_enable_msi_exact() instead of pci_enable_msi_block()" pci_enable_msi_exact is used which fails if the desired number of MSI's was not possible to allocate. Change GenWQE to use pci_enable_msi_range to restore the old behavior.

---
 drivers/misc/genwqe/card_ddcb.c  |  4 +---
 drivers/misc/genwqe/card_utils.c | 10 ++++++----
 2 files changed, 7 insertions(+), 7 deletions(-)
drivers/misc/genwqe/card_ddcb.c +1 -3
index c8046db..f66d43d 100644
@@ -1237,9 +1237,7 @@ int genwqe_setup_service_layer(struct genwqe_dev *cd)
 	}
 
 	rc = genwqe_set_interrupt_capability(cd, GENWQE_MSI_IRQS);
-	if (rc > 0)
-		rc = genwqe_set_interrupt_capability(cd, rc);
-	if (rc != 0) {
+	if (rc) {
 		rc = -ENODEV;
 		goto stop_kthread;
 	}
drivers/misc/genwqe/card_utils.c +6 -4
index 62cc6bb..6abc437 100644
@@ -718,10 +718,12 @@ int genwqe_set_interrupt_capability(struct genwqe_dev *cd, int count)
 	int rc;
 	struct pci_dev *pci_dev = cd->pci_dev;
 
-	rc = pci_enable_msi_exact(pci_dev, count);
-	if (rc == 0)
-		cd->flags |= GENWQE_FLAG_MSI_ENABLED;
-	return rc;
+	rc = pci_enable_msi_range(pci_dev, 1, count);
+	if (rc < 0)
+		return rc;
+
+	cd->flags |= GENWQE_FLAG_MSI_ENABLED;
+	return 0;
 }
 
 /**
Signature · 1 line
1.9.3
Quoted 2 lines

I am curious though why would you need convert error code to -ENODEV here (and throughout the code in general)?

Yes, I thought about that too but decided to just fix the bug and not change this (since it's more or less unrelated).

Regards,
Sebastian

Reviewed-by
#3 lore raw

Hi Sebastian,

Am Mittwoch, den 09.07.2014, 13:44 +0200 schrieb Sebastian Ott:

Quoted 55 lines · Alexander Gordeev
Quoted 54 lines · Sebastian Ott
Quoted 52 lines

GenWQE used to call pci_enable_msi_block to allocate a desired number of MSI's. If that was not possible pci_enable_msi_block returned with a smaller number which might be possible to allocate. GenWQE then called pci_enable_msi_block with that number.

Since commit a30d0108b
"GenWQE: Use pci_enable_msi_exact() instead of pci_enable_msi_block()" pci_enable_msi_exact is used which fails if the desired number of MSI's was not possible to allocate. Change GenWQE to use pci_enable_msi_range to restore the old behavior.

---
 drivers/misc/genwqe/card_ddcb.c  |  4 +---
 drivers/misc/genwqe/card_utils.c | 10 ++++++----
 2 files changed, 7 insertions(+), 7 deletions(-)
drivers/misc/genwqe/card_ddcb.c +1 -3
index c8046db..f66d43d 100644
@@ -1237,9 +1237,7 @@ int genwqe_setup_service_layer(struct genwqe_dev *cd)
 	}
 
 	rc = genwqe_set_interrupt_capability(cd, GENWQE_MSI_IRQS);
-	if (rc > 0)
-		rc = genwqe_set_interrupt_capability(cd, rc);
-	if (rc != 0) {
+	if (rc) {
 		rc = -ENODEV;
 		goto stop_kthread;
 	}
drivers/misc/genwqe/card_utils.c +6 -4
index 62cc6bb..6abc437 100644
@@ -718,10 +718,12 @@ int genwqe_set_interrupt_capability(struct genwqe_dev *cd, int count)
 	int rc;
 	struct pci_dev *pci_dev = cd->pci_dev;
 
-	rc = pci_enable_msi_exact(pci_dev, count);
-	if (rc == 0)
-		cd->flags |= GENWQE_FLAG_MSI_ENABLED;
-	return rc;
+	rc = pci_enable_msi_range(pci_dev, 1, count);
+	if (rc < 0)
+		return rc;
+
+	cd->flags |= GENWQE_FLAG_MSI_ENABLED;
+	return 0;
 }
 
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
drivers/misc/genwqe/card_utils.c +0 -0
 /**
Signature · 1 line
1.9.3

thanks for the fix and Alexander for reviewing it.

Quoted 8 lines
Quoted 2 lines

I am curious though why would you need convert error code to -ENODEV here (and throughout the code in general)?

Yes, I thought about that too but decided to just fix the bug and not change this (since it's more or less unrelated).

Regards,
Sebastian

You are probably right, converting the return code into -ENODEV is not really needed.

maintainer
#4 lore raw
In reply to Sebastian Ott

[+cc linux-pci]

Quoted 5 lines · Sebastian Ott

GenWQE used to call pci_enable_msi_block to allocate a desired number of MSI's. If that was not possible pci_enable_msi_block returned with a smaller number which might be possible to allocate. GenWQE then called pci_enable_msi_block with that number.

Quoted 7 lines

Since commit a30d0108b
"GenWQE: Use pci_enable_msi_exact() instead of pci_enable_msi_block()" pci_enable_msi_exact is used which fails if the desired number of MSI's was not possible to allocate. Change GenWQE to use pci_enable_msi_range to restore the old behavior.

Since this fixes a30d0108b09a, which we merged via my tree in v3.16-rc1, I applied this with Alexander and Frank's acks to for-linus for v3.16, thanks!

Quoted 44 lines
---
 drivers/misc/genwqe/card_ddcb.c  |  4 +---
 drivers/misc/genwqe/card_utils.c | 10 ++++++----
 2 files changed, 7 insertions(+), 7 deletions(-)
drivers/misc/genwqe/card_ddcb.c +1 -3
index c8046db..f66d43d 100644
@@ -1237,9 +1237,7 @@ int genwqe_setup_service_layer(struct genwqe_dev *cd)
 	}
 
 	rc = genwqe_set_interrupt_capability(cd, GENWQE_MSI_IRQS);
-	if (rc > 0)
-		rc = genwqe_set_interrupt_capability(cd, rc);
-	if (rc != 0) {
+	if (rc) {
 		rc = -ENODEV;
 		goto stop_kthread;
 	}
drivers/misc/genwqe/card_utils.c +6 -4
index 62cc6bb..6abc437 100644
@@ -718,10 +718,12 @@ int genwqe_set_interrupt_capability(struct genwqe_dev *cd, int count)
 	int rc;
 	struct pci_dev *pci_dev = cd->pci_dev;
 
-	rc = pci_enable_msi_exact(pci_dev, count);
-	if (rc == 0)
-		cd->flags |= GENWQE_FLAG_MSI_ENABLED;
-	return rc;
+	rc = pci_enable_msi_range(pci_dev, 1, count);
+	if (rc < 0)
+		return rc;
+
+	cd->flags |= GENWQE_FLAG_MSI_ENABLED;
+	return 0;
 }
 
 /**
Signature · 1 line
1.9.3
#5 lore raw

Hi Bjorn and Sebastian,

Am Mittwoch, den 16.07.2014, 15:10 -0600 schrieb Bjorn Helgaas:

Quoted 48 lines

[+cc linux-pci]

Quoted 5 lines · Sebastian Ott

GenWQE used to call pci_enable_msi_block to allocate a desired number of MSI's. If that was not possible pci_enable_msi_block returned with a smaller number which might be possible to allocate. GenWQE then called pci_enable_msi_block with that number.

Quoted 7 lines

Since commit a30d0108b
"GenWQE: Use pci_enable_msi_exact() instead of pci_enable_msi_block()" pci_enable_msi_exact is used which fails if the desired number of MSI's was not possible to allocate. Change GenWQE to use pci_enable_msi_range to restore the old behavior.

Since this fixes a30d0108b09a, which we merged via my tree in v3.16-rc1, I applied this with Alexander and Frank's acks to for-linus for v3.16, thanks!

Quoted 28 lines
---
 drivers/misc/genwqe/card_ddcb.c  |  4 +---
 drivers/misc/genwqe/card_utils.c | 10 ++++++----
 2 files changed, 7 insertions(+), 7 deletions(-)
drivers/misc/genwqe/card_ddcb.c +1 -3
index c8046db..f66d43d 100644
@@ -1237,9 +1237,7 @@ int genwqe_setup_service_layer(struct genwqe_dev *cd)
 	}
 
 	rc = genwqe_set_interrupt_capability(cd, GENWQE_MSI_IRQS);
-	if (rc > 0)
-		rc = genwqe_set_interrupt_capability(cd, rc);
-	if (rc != 0) {
+	if (rc) {
 		rc = -ENODEV;
 		goto stop_kthread;
 	}
drivers/misc/genwqe/card_utils.c +0 -0
index 62cc6bb..6abc437 100644
@@ -718,10 +718,12 @@ int genwqe_set_interrupt_capability(struct genwqe_dev *cd, int count)
 	int rc;
 	struct pci_dev *pci_dev = cd->pci_dev;
 
Quoted 11 lines

drivers/misc/genwqe/card_utils.c int genwqe_set_interrupt_capability(struct genwqe_dev *cd, int count) · line 727

Quoted 11 lines
drivers/misc/genwqe/card_utils.c +6 -4
-	rc = pci_enable_msi_exact(pci_dev, count);
-	if (rc == 0)
-		cd->flags |= GENWQE_FLAG_MSI_ENABLED;
-	return rc;
+	rc = pci_enable_msi_range(pci_dev, 1, count);
+	if (rc < 0)
+		return rc;
+
+	cd->flags |= GENWQE_FLAG_MSI_ENABLED;
+	return 0;
 }

The original code tried to register for 4 interrupts. On my system the following scenario was executed:

We tried to register for 4 MSI interrupts, which was the original plan of interrupts for the card. Linux returned that it could not do that and that just 1 would work. We tried to register for 1 MSI interrupt and it worked. GENWQE_MSI_IRQS is still 4. That is how my original version looked like:

        rc = genwqe_set_interrupt_capability(cd, GENWQE_MSI_IRQS);
        if (rc > 0)
                rc = genwqe_set_interrupt_capability(cd, rc);
        if (rc != 0) {
                rc = -ENODEV;
                goto stop_kthread;
        }

So genwqe_set_interrupt_capability() was indeed called two times. Calling it with 4 returned with rc=1 and no interrupts enabled. So calling it a 2nd time with rc=1 was leading to the proper enablement.

I think the simplest way is to set GENWQE_MSI_IRQS to 1. The rest of the code at least assumes just one interrupt, because 4 never worked.

Regards

Frank

#6 lore raw
Quoted 66 lines · Frank Haverkamp

Hi Bjorn and Sebastian,

Am Mittwoch, den 16.07.2014, 15:10 -0600 schrieb Bjorn Helgaas:

Quoted 48 lines

[+cc linux-pci]

Quoted 5 lines · Sebastian Ott

GenWQE used to call pci_enable_msi_block to allocate a desired number of MSI's. If that was not possible pci_enable_msi_block returned with a smaller number which might be possible to allocate. GenWQE then called pci_enable_msi_block with that number.

Quoted 7 lines

Since commit a30d0108b
"GenWQE: Use pci_enable_msi_exact() instead of pci_enable_msi_block()" pci_enable_msi_exact is used which fails if the desired number of MSI's was not possible to allocate. Change GenWQE to use pci_enable_msi_range to restore the old behavior.

Since this fixes a30d0108b09a, which we merged via my tree in v3.16-rc1, I applied this with Alexander and Frank's acks to for-linus for v3.16, thanks!

Quoted 28 lines
---
 drivers/misc/genwqe/card_ddcb.c  |  4 +---
 drivers/misc/genwqe/card_utils.c | 10 ++++++----
 2 files changed, 7 insertions(+), 7 deletions(-)
drivers/misc/genwqe/card_ddcb.c +1 -3
index c8046db..f66d43d 100644
@@ -1237,9 +1237,7 @@ int genwqe_setup_service_layer(struct genwqe_dev *cd)
 	}
 
 	rc = genwqe_set_interrupt_capability(cd, GENWQE_MSI_IRQS);
-	if (rc > 0)
-		rc = genwqe_set_interrupt_capability(cd, rc);
-	if (rc != 0) {
+	if (rc) {
 		rc = -ENODEV;
 		goto stop_kthread;
 	}
drivers/misc/genwqe/card_utils.c +0 -0
index 62cc6bb..6abc437 100644
@@ -718,10 +718,12 @@ int genwqe_set_interrupt_capability(struct genwqe_dev *cd, int count)
 	int rc;
 	struct pci_dev *pci_dev = cd->pci_dev;
 
Quoted 11 lines

drivers/misc/genwqe/card_utils.c int genwqe_set_interrupt_capability(struct genwqe_dev *cd, int count) · line 727

Quoted 11 lines
drivers/misc/genwqe/card_utils.c +6 -4
-	rc = pci_enable_msi_exact(pci_dev, count);
-	if (rc == 0)
-		cd->flags |= GENWQE_FLAG_MSI_ENABLED;
-	return rc;
+	rc = pci_enable_msi_range(pci_dev, 1, count);
+	if (rc < 0)
+		return rc;
+
+	cd->flags |= GENWQE_FLAG_MSI_ENABLED;
+	return 0;
 }

The original code tried to register for 4 interrupts. On my system the following scenario was executed:

Quoted 5 lines

We tried to register for 4 MSI interrupts, which was the original plan of interrupts for the card. Linux returned that it could not do that and that just 1 would work. We tried to register for 1 MSI interrupt and it worked. GENWQE_MSI_IRQS is still 4. That is how my original version looked like:

I changed the code that way, because I was under the impression GENWQE_MSI_IRQS was set to 4 for a reason (I have no knowledge of the internal workings of this driver). A lot of archs don't support more than one MSI anyway - but are you saying that the genwqe card/driver itself doesn't support more than one MSI?

Regards,
Sebastian

Quoted 21 lines
        rc = genwqe_set_interrupt_capability(cd, GENWQE_MSI_IRQS);
        if (rc > 0)
                rc = genwqe_set_interrupt_capability(cd, rc);
        if (rc != 0) {
                rc = -ENODEV;
                goto stop_kthread;
        }

So genwqe_set_interrupt_capability() was indeed called two times. Calling it with 4 returned with rc=1 and no interrupts enabled. So calling it a 2nd time with rc=1 was leading to the proper enablement.

I think the simplest way is to set GENWQE_MSI_IRQS to 1. The rest of the code at least assumes just one interrupt, because 4 never worked.

Regards

Frank

maintainer
#7 lore raw
Quoted 73 lines · Sebastian Ott
Quoted 66 lines · Frank Haverkamp

Hi Bjorn and Sebastian,

Am Mittwoch, den 16.07.2014, 15:10 -0600 schrieb Bjorn Helgaas:

Quoted 48 lines

[+cc linux-pci]

Quoted 5 lines · Sebastian Ott

GenWQE used to call pci_enable_msi_block to allocate a desired number of MSI's. If that was not possible pci_enable_msi_block returned with a smaller number which might be possible to allocate. GenWQE then called pci_enable_msi_block with that number.

Quoted 7 lines

Since commit a30d0108b
"GenWQE: Use pci_enable_msi_exact() instead of pci_enable_msi_block()" pci_enable_msi_exact is used which fails if the desired number of MSI's was not possible to allocate. Change GenWQE to use pci_enable_msi_range to restore the old behavior.

Since this fixes a30d0108b09a, which we merged via my tree in v3.16-rc1, I applied this with Alexander and Frank's acks to for-linus for v3.16, thanks!

Quoted 28 lines
---
 drivers/misc/genwqe/card_ddcb.c  |  4 +---
 drivers/misc/genwqe/card_utils.c | 10 ++++++----
 2 files changed, 7 insertions(+), 7 deletions(-)
drivers/misc/genwqe/card_ddcb.c +1 -3
index c8046db..f66d43d 100644
@@ -1237,9 +1237,7 @@ int genwqe_setup_service_layer(struct genwqe_dev *cd)
  }
 
  rc = genwqe_set_interrupt_capability(cd, GENWQE_MSI_IRQS);
- if (rc > 0)
-         rc = genwqe_set_interrupt_capability(cd, rc);
- if (rc != 0) {
+ if (rc) {
          rc = -ENODEV;
          goto stop_kthread;
  }
drivers/misc/genwqe/card_utils.c +0 -0
index 62cc6bb..6abc437 100644
@@ -718,10 +718,12 @@ int genwqe_set_interrupt_capability(struct genwqe_dev *cd, int count)
  int rc;
  struct pci_dev *pci_dev = cd->pci_dev;
 
Quoted 11 lines

drivers/misc/genwqe/card_utils.c int genwqe_set_interrupt_capability(struct genwqe_dev *cd, int count) · line 727

Quoted 11 lines
drivers/misc/genwqe/card_utils.c +6 -4
- rc = pci_enable_msi_exact(pci_dev, count);
- if (rc == 0)
-         cd->flags |= GENWQE_FLAG_MSI_ENABLED;
- return rc;
+ rc = pci_enable_msi_range(pci_dev, 1, count);
+ if (rc < 0)
+         return rc;
+
+ cd->flags |= GENWQE_FLAG_MSI_ENABLED;
+ return 0;
 }

The original code tried to register for 4 interrupts. On my system the following scenario was executed:

Quoted 5 lines

We tried to register for 4 MSI interrupts, which was the original plan of interrupts for the card. Linux returned that it could not do that and that just 1 would work. We tried to register for 1 MSI interrupt and it worked. GENWQE_MSI_IRQS is still 4. That is how my original version looked like:

Quoted 27 lines

I changed the code that way, because I was under the impression GENWQE_MSI_IRQS was set to 4 for a reason (I have no knowledge of the internal workings of this driver). A lot of archs don't support more than one MSI anyway - but are you saying that the genwqe card/driver itself doesn't support more than one MSI?

Regards,
Sebastian

Quoted 19 lines
        rc = genwqe_set_interrupt_capability(cd, GENWQE_MSI_IRQS);
        if (rc > 0)
                rc = genwqe_set_interrupt_capability(cd, rc);
        if (rc != 0) {
                rc = -ENODEV;
                goto stop_kthread;
        }

So genwqe_set_interrupt_capability() was indeed called two times. Calling it with 4 returned with rc=1 and no interrupts enabled. So calling it a 2nd time with rc=1 was leading to the proper enablement.

I think the simplest way is to set GENWQE_MSI_IRQS to 1. The rest of the code at least assumes just one interrupt, because 4 never worked.

Regards

Frank

OK, I dropped this patch from for-linus until this gets sorted out. If you need any changes before v3.16, they'll have to be merged via some other route, because I'll be on vacation until v3.16 releases.

Bjorn