Skip to contentSkip to conversation

xen/pirq: fix error path cleanup when binding MSIs

PATCH In review Roger Pau Monne 4 participants 9 messages Feb 28, 2018 – Mar 15, 2018

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

PATCH 1/1 xen/pirq: fix error path cleanup when binding MSIs

Current cleanup in the error path of xen_bind_pirq_msi_to_irq is wrong. First of all there's an off-by-one in the cleanup loop, which can lead to unbinding wrong IRQs.

Secondly IRQs not bound won't be freed, thus leaking IRQ numbers.

Note that there's no need to differentiate between bound and unbound IRQs when freeing them, __unbind_from_irq will deal with both of them correctly.

Fixes 4892c9b4ada9f9 ("xen: add support for MSI message groups")

---
Cc: Boris Ostrovsky <[email protected]>
Cc: Juergen Gross <[email protected]>
Cc: Amit Shah <[email protected]>
CC: [email protected]
Cc: [email protected]

---
 drivers/xen/events/events_base.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/xen/events/events_base.c +2 -2
index b241bfa529ce..159faf1269fb 100644
@@ -763,8 +763,8 @@ int xen_bind_pirq_msi_to_irq(struct pci_dev *dev, struct msi_desc *msidesc,
 	mutex_unlock(&irq_mapping_update_lock);
 	return irq;
 error_irq:
-	for (; i >= 0; i--)
-		__unbind_from_irq(irq + i);
+	while (nvec--)
+		__unbind_from_irq(irq + nvec);
 	mutex_unlock(&irq_mapping_update_lock);
 	return ret;
 }
Signature · 1 line
2.16.1
Reviewed-by Amit Shah on v1 1/1
#1 lore raw
Quoted 37 lines · Roger Pau Monne

Current cleanup in the error path of xen_bind_pirq_msi_to_irq is wrong. First of all there's an off-by-one in the cleanup loop, which can lead to unbinding wrong IRQs.

Secondly IRQs not bound won't be freed, thus leaking IRQ numbers.

Note that there's no need to differentiate between bound and unbound IRQs when freeing them, __unbind_from_irq will deal with both of them correctly.

Fixes 4892c9b4ada9f9 ("xen: add support for MSI message groups")

---
Cc: Boris Ostrovsky <[email protected]>
Cc: Juergen Gross <[email protected]>
Cc: Amit Shah <[email protected]>
CC: [email protected]
Cc: [email protected]
---
 drivers/xen/events/events_base.c | 4 ++--

 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/xen/events/events_base.c +0 -0
index b241bfa529ce..159faf1269fb 100644
@@ -763,8 +763,8 @@ int xen_bind_pirq_msi_to_irq(struct pci_dev *dev,
 struct msi_desc *msidesc,
  	mutex_unlock(&irq_mapping_update_lock);
  	return irq;

 error_irq:

drivers/xen/events/events_base.c +2 -2
-	for (; i >= 0; i--)
-		__unbind_from_irq(irq + i);
+	while (nvec--)
+		__unbind_from_irq(irq + nvec);
Quoted 3 lines

  mutex_unlock(&irq_mapping_update_lock);
  return ret;
 }

Amit

Amazon Development Center Germany GmbH
Berlin - Dresden - Aachen
main office: Krausenstr. 38, 10117 Berlin
Geschaeftsfuehrer: Dr. Ralf Herbrich, Christian Schlaeger
Ust-ID: DE289237879
Eingetragen am Amtsgericht Charlottenburg HRB 149173 B

Reviewed-by
#2 lore raw
Quoted 34 lines · Amit
Quoted 33 lines · Roger Pau Monne

Current cleanup in the error path of xen_bind_pirq_msi_to_irq is wrong. First of all there's an off-by-one in the cleanup loop, which can lead to unbinding wrong IRQs.

Secondly IRQs not bound won't be freed, thus leaking IRQ numbers.

Note that there's no need to differentiate between bound and unbound IRQs when freeing them, __unbind_from_irq will deal with both of them correctly.

Fixes 4892c9b4ada9f9 ("xen: add support for MSI message groups")

---
Cc: Boris Ostrovsky <[email protected]>
Cc: Juergen Gross <[email protected]>
Cc: Amit Shah <[email protected]>
CC: [email protected]
Cc: [email protected]
---
 drivers/xen/events/events_base.c | 4 ++--

 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/xen/events/events_base.c +0 -0
index b241bfa529ce..159faf1269fb 100644
@@ -763,8 +763,8 @@ int xen_bind_pirq_msi_to_irq(struct pci_dev *dev,
 struct msi_desc *msidesc,
  	mutex_unlock(&irq_mapping_update_lock);
  	return irq;

 error_irq:

Quoted 8 lines
Quoted 7 lines
drivers/xen/events/events_base.c +2 -2
-	for (; i >= 0; i--)
-		__unbind_from_irq(irq + i);
+	while (nvec--)
+		__unbind_from_irq(irq + nvec);

  mutex_unlock(&irq_mapping_update_lock);
  return ret;
 }

Reviewed-by
#3 lore raw
In reply to Shah, Amit
Quoted 34 lines · Amit
Quoted 33 lines · Roger Pau Monne

Current cleanup in the error path of xen_bind_pirq_msi_to_irq is wrong. First of all there's an off-by-one in the cleanup loop, which can lead to unbinding wrong IRQs.

Secondly IRQs not bound won't be freed, thus leaking IRQ numbers.

Note that there's no need to differentiate between bound and unbound IRQs when freeing them, __unbind_from_irq will deal with both of them correctly.

Fixes 4892c9b4ada9f9 ("xen: add support for MSI message groups")

---
Cc: Boris Ostrovsky <[email protected]>
Cc: Juergen Gross <[email protected]>
Cc: Amit Shah <[email protected]>
CC: [email protected]
Cc: [email protected]
---
 drivers/xen/events/events_base.c | 4 ++--

 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/xen/events/events_base.c +0 -0
index b241bfa529ce..159faf1269fb 100644
@@ -763,8 +763,8 @@ int xen_bind_pirq_msi_to_irq(struct pci_dev *dev,
 struct msi_desc *msidesc,
  	mutex_unlock(&irq_mapping_update_lock);
  	return irq;

 error_irq:

Quoted 8 lines
Quoted 7 lines
drivers/xen/events/events_base.c +2 -2
-	for (; i >= 0; i--)
-		__unbind_from_irq(irq + i);
+	while (nvec--)
+		__unbind_from_irq(irq + nvec);

  mutex_unlock(&irq_mapping_update_lock);
  return ret;
 }

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

Reviewed-by Amit Shah on v1 1/1
#4 lore raw
In reply to Roger Pau Monne
Quoted 37 lines · Roger Pau Monne

Current cleanup in the error path of xen_bind_pirq_msi_to_irq is wrong. First of all there's an off-by-one in the cleanup loop, which can lead to unbinding wrong IRQs.

Secondly IRQs not bound won't be freed, thus leaking IRQ numbers.

Note that there's no need to differentiate between bound and unbound IRQs when freeing them, __unbind_from_irq will deal with both of them correctly.

Fixes 4892c9b4ada9f9 ("xen: add support for MSI message groups")

---
Cc: Boris Ostrovsky <[email protected]>
Cc: Juergen Gross <[email protected]>
Cc: Amit Shah <[email protected]>
CC: [email protected]
Cc: [email protected]
---
 drivers/xen/events/events_base.c | 4 ++--

 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/xen/events/events_base.c +0 -0
index b241bfa529ce..159faf1269fb 100644
@@ -763,8 +763,8 @@ int xen_bind_pirq_msi_to_irq(struct pci_dev *dev,
 struct msi_desc *msidesc,
  	mutex_unlock(&irq_mapping_update_lock);
  	return irq;

 error_irq:

drivers/xen/events/events_base.c +2 -2
-	for (; i >= 0; i--)
-		__unbind_from_irq(irq + i);
+	while (nvec--)
+		__unbind_from_irq(irq + nvec);
Quoted 3 lines

  mutex_unlock(&irq_mapping_update_lock);
  return ret;
 }

Amit

Amazon Development Center Germany GmbH
Berlin - Dresden - Aachen
main office: Krausenstr. 38, 10117 Berlin
Geschaeftsfuehrer: Dr. Ralf Herbrich, Christian Schlaeger
Ust-ID: DE289237879
Eingetragen am Amtsgericht Charlottenburg HRB 149173 B
_______________________________________________
Xen-devel mailing list [email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

maintainer
#5 lore raw
In reply to Roger Pau Monne
Quoted 6 lines · Roger Pau Monne

Current cleanup in the error path of xen_bind_pirq_msi_to_irq is wrong. First of all there's an off-by-one in the cleanup loop, which can lead to unbinding wrong IRQs.

Secondly IRQs not bound won't be freed, thus leaking IRQ numbers.

Quoted 7 lines

Note that there's no need to differentiate between bound and unbound IRQs when freeing them, __unbind_from_irq will deal with both of them correctly.

Fixes 4892c9b4ada9f9 ("xen: add support for MSI message groups")

Committed to xen/tip for-linus-4.16a

Juergen

maintainer
#6 lore raw
In reply to Roger Pau Monne
Quoted 6 lines · Roger Pau Monne

Current cleanup in the error path of xen_bind_pirq_msi_to_irq is wrong. First of all there's an off-by-one in the cleanup loop, which can lead to unbinding wrong IRQs.

Secondly IRQs not bound won't be freed, thus leaking IRQ numbers.

Quoted 7 lines

Note that there's no need to differentiate between bound and unbound IRQs when freeing them, __unbind_from_irq will deal with both of them correctly.

Fixes 4892c9b4ada9f9 ("xen: add support for MSI message groups")

Committed to xen/tip for-linus-4.16a

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#7 lore raw
In reply to Roger Pau Monne
Quoted 13 lines · Roger Pau Monne

Current cleanup in the error path of xen_bind_pirq_msi_to_irq is wrong. First of all there's an off-by-one in the cleanup loop, which can lead to unbinding wrong IRQs.

Secondly IRQs not bound won't be freed, thus leaking IRQ numbers.

Note that there's no need to differentiate between bound and unbound IRQs when freeing them, __unbind_from_irq will deal with both of them correctly.

Fixes 4892c9b4ada9f9 ("xen: add support for MSI message groups")
Quoted 6 lines

---
Cc: Boris Ostrovsky <[email protected]>
Cc: Juergen Gross <[email protected]>
Cc: Amit Shah <[email protected]>
CC: [email protected]
Cc: [email protected]

The CC to stable got lost on commit, so this didn't actually make it to the stable queue.  Can you please get it queued?

Thanks,
Amazon Development Center Germany GmbH
Berlin - Dresden - Aachen
main office: Krausenstr. 38, 10117 Berlin
Geschaeftsfuehrer: Dr. Ralf Herbrich, Christian Schlaeger
Ust-ID: DE289237879
Eingetragen am Amtsgericht Charlottenburg HRB 149173 B

#8 lore raw
In reply to Roger Pau Monne
Quoted 13 lines · Roger Pau Monne

Current cleanup in the error path of xen_bind_pirq_msi_to_irq is wrong. First of all there's an off-by-one in the cleanup loop, which can lead to unbinding wrong IRQs.

Secondly IRQs not bound won't be freed, thus leaking IRQ numbers.

Note that there's no need to differentiate between bound and unbound IRQs when freeing them, __unbind_from_irq will deal with both of them correctly.

Fixes 4892c9b4ada9f9 ("xen: add support for MSI message groups")
Quoted 6 lines

---
Cc: Boris Ostrovsky <[email protected]>
Cc: Juergen Gross <[email protected]>
Cc: Amit Shah <[email protected]>
CC: [email protected]
Cc: [email protected]

The CC to stable got lost on commit, so this didn't actually make it to the stable queue.  Can you please get it queued?

Thanks,
Amazon Development Center Germany GmbH
Berlin - Dresden - Aachen
main office: Krausenstr. 38, 10117 Berlin
Geschaeftsfuehrer: Dr. Ralf Herbrich, Christian Schlaeger
Ust-ID: DE289237879
Eingetragen am Amtsgericht Charlottenburg HRB 149173 B
_______________________________________________
Xen-devel mailing list [email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel