Skip to contentSkip to conversation

xen: fix the error handling of msi setup

PATCH In review Qing He 2 participants 3 messages Aug 28, 2009

Subsystems (3)
lore
Share & tools
lore

Qing He

author
#0 lore raw

PATCH 1/2 xen: fix the error handling of msi setup

Fix the error handling of msi setup, the return value of failure is -1, not 0.

---
 arch/x86/xen/pci.c   |    5 ++---
 drivers/xen/events.c |    4 ++--
 2 files changed, 4 insertions(+), 5 deletions(-)
arch/x86/xen/pci.c +2 -3
index 60bab67..44d91ad 100644
@@ -90,13 +90,12 @@ void __init xen_setup_pirqs(void)
 #ifdef CONFIG_PCI_MSI
 int xen_setup_msi_irqs(struct pci_dev *dev, int nvec, int type)
 {
-	unsigned int irq;
-	int ret;
+	int irq, ret;
 	struct msi_desc *msidesc;
 
 	list_for_each_entry(msidesc, &dev->msi_list, list) {
 		irq = xen_create_msi_irq(dev, msidesc, type);
-		if (irq == 0)
+		if (irq < 0)
 			return -1;
 
 		ret = set_irq_msi(irq, msidesc);
drivers/xen/events.c +2 -2
index 007b1d7..a3d430b 100644
@@ -591,7 +591,7 @@ int xen_destroy_irq(int irq)
 	unmap_irq.domid = DOMID_SELF;
 	rc = HYPERVISOR_physdev_op(PHYSDEVOP_unmap_pirq, &unmap_irq);
 	if (rc) {
-		printk(KERN_WARNING "unmap irq failed %x\n", rc);
+		printk(KERN_WARNING "unmap irq failed %d\n", rc);
 		goto out;
 	}
 
@@ -643,7 +643,7 @@ int xen_create_msi_irq(struct pci_dev *dev, struct msi_desc *msidesc, int type)
 	rc = HYPERVISOR_physdev_op(PHYSDEVOP_map_pirq, &map_irq);
 	if (rc) {
 
-		printk(KERN_WARNING "xen map irq failed %x\n", rc);
+		printk(KERN_WARNING "xen map irq failed %d\n", rc);
 
 		dynamic_irq_cleanup(irq);
author
#1 lore raw

PATCH 2/2 xen: decouple irq and pirq for MSI

don't assume irq == pirq, let xen to allocation pirq instead

---
 drivers/xen/events.c |   25 +++++++++++++------------
 1 files changed, 13 insertions(+), 12 deletions(-)
drivers/xen/events.c +13 -12
index a3d430b..2a44456 100644
@@ -89,7 +89,7 @@ struct irq_info
 		unsigned short virq;
 		enum ipi_vector ipi;
 		struct {
-			unsigned short gsi;
+			unsigned short nr;
 			unsigned char vector;
 			unsigned char flags;
 		} pirq;
@@ -140,10 +140,10 @@ static struct irq_info mk_virq_info(unsigned short evtchn, unsigned short virq)
 }
 
 static struct irq_info mk_pirq_info(unsigned short evtchn,
-				    unsigned short gsi, unsigned short vector)
+				    unsigned short pirq, unsigned short vector)
 {
 	return (struct irq_info) { .type = IRQT_PIRQ, .evtchn = evtchn,
-			.cpu = 0, .u.pirq = { .gsi = gsi, .vector = vector } };
+			.cpu = 0, .u.pirq = { .nr = pirq, .vector = vector } };
 }
 
 /*
@@ -192,7 +192,7 @@ static unsigned gsi_from_irq(unsigned irq)
 	BUG_ON(info == NULL);
 	BUG_ON(info->type != IRQT_PIRQ);
 
-	return info->u.pirq.gsi;
+	return info->u.pirq.nr;
 }
 
 static unsigned vector_from_irq(unsigned irq)
@@ -387,7 +387,8 @@ static bool identity_mapped_irq(unsigned irq)
 
 static void pirq_unmask_notify(int irq)
 {
-	struct physdev_eoi eoi = { .irq = irq };
+	struct irq_info *info = info_for_irq(irq);
+	struct physdev_eoi eoi = { .irq = info->u.pirq.nr };
 
 	if (unlikely(pirq_needs_eoi(irq))) {
 		int rc = HYPERVISOR_physdev_op(PHYSDEVOP_eoi, &eoi);
@@ -402,7 +403,7 @@ static void pirq_query_unmask(int irq)
 
 	BUG_ON(info->type != IRQT_PIRQ);
 
-	irq_status.irq = irq;
+	irq_status.irq = info->u.pirq.nr;
 	if (HYPERVISOR_physdev_op(PHYSDEVOP_irq_status_query, &irq_status))
 		irq_status.flags = 0;
 
@@ -430,7 +431,7 @@ static unsigned int startup_pirq(unsigned int irq)
 	if (VALID_EVTCHN(evtchn))
 		goto out;
 
-	bind_pirq.pirq = irq;
+	bind_pirq.pirq = info->u.pirq.nr;
 	/* NB. We are happy to share unless we are probing. */
 	bind_pirq.flags = probing_irq(irq) ? 0 : BIND_PIRQ__WILL_SHARE;
 	rc = HYPERVISOR_event_channel_op(EVTCHNOP_bind_pirq, &bind_pirq);
@@ -561,7 +562,7 @@ int xen_allocate_pirq(unsigned gsi, char *name)
 	set_irq_chip_and_handler_name(irq, &xen_pirq_chip,
 				      handle_level_irq, name);
 
-	irq_op.irq = irq;
+	irq_op.irq = gsi;
 	if (HYPERVISOR_physdev_op(PHYSDEVOP_alloc_irq_vector, &irq_op)) {
 		dynamic_irq_cleanup(irq);
 		irq = -ENOSPC;
@@ -579,6 +580,7 @@ int xen_destroy_irq(int irq)
 {
 	struct irq_desc *desc;
 	struct physdev_unmap_pirq unmap_irq;
+	struct irq_info *info = info_for_irq(irq);
 	int rc = -ENOENT;
 
 	spin_lock(&irq_mapping_update_lock);
@@ -587,7 +589,7 @@ int xen_destroy_irq(int irq)
 	if (!desc)
 		goto out;
 
-	unmap_irq.pirq = irq;
+	unmap_irq.pirq = info->u.pirq.nr;
 	unmap_irq.domid = DOMID_SELF;
 	rc = HYPERVISOR_physdev_op(PHYSDEVOP_unmap_pirq, &unmap_irq);
 	if (rc) {
@@ -617,6 +619,7 @@ int xen_create_msi_irq(struct pci_dev *dev, struct msi_desc *msidesc, int type)
 	map_irq.domid = domid;
 	map_irq.type = MAP_PIRQ_TYPE_MSI;
 	map_irq.index = -1;
+	map_irq.pirq = -1;
 	map_irq.bus = dev->bus->number;
 	map_irq.devfn = dev->devfn;
 
@@ -638,8 +641,6 @@ int xen_create_msi_irq(struct pci_dev *dev, struct msi_desc *msidesc, int type)
 	if (irq == -1)
 		goto out;
 
-	map_irq.pirq = irq;
-
 	rc = HYPERVISOR_physdev_op(PHYSDEVOP_map_pirq, &map_irq);
 	if (rc) {
 
@@ -651,7 +652,7 @@ int xen_create_msi_irq(struct pci_dev *dev, struct msi_desc *msidesc, int type)
 		goto out;
 	}
 
-	irq_info[irq] = mk_pirq_info(0, -1, map_irq.index);
+	irq_info[irq] = mk_pirq_info(0, map_irq.pirq, map_irq.index);
 	set_irq_chip_and_handler_name(irq, &xen_pirq_chip,
 			handle_level_irq,
 			(type == PCI_CAP_ID_MSIX) ? "msi-x":"msi");