Skip to contentSkip to conversation

Linux patch "translate Xen-provided PIRQs"

DISCUSSION Jan Beulich 2 participants 2 messages Sep 8, 2008 2 messages not in the archive

Subsystems (3)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): C4E80558.1CE83%[email protected]

A message that is not in the archive (sent off-list or not yet received): C4E83A6B.1CE8D%[email protected]

#2 lore raw
Quoted 16 lines
Quoted 1 line
Quoted 1 line

Keir Fraser <[email protected]> 06.09.08 14:47 >>>

Quoted 7 lines · Keir Fraser

I reverted this from the tree since it breaks the -xenU build and also mainly because I thought it was responsible for breaking our automated tests. Actually I'm not so sure about the latter, and the build breakage is easily fixed. I'll do some more investigation on Monday and reinstate the patch (with build fix) if it looks okay to do so.

-- Keir

Jan,

I fixed the build failure easily enough by making the ifdef-else'ed definition of NR_PIRQS check for defined(MAX_IO_APICS).

Quoted 6 lines

However, save/restore is definitely broken (I got the same result with both default -xen and -xenU configs). The appended backtrace is reported immediately upon resume (it's the only BUG_ON in restore_cpu_ipis()). I don't get this failure with the patch reverted (although automated tests are still failing save/restore for some unknown reason; but it works for me manually).

Pretty easily fixed - there was another place where the width of the event channel part of the irq_info array was hard-coded to 16 bits, which I overlooked. New patch below.

Quoted 4 lines

I'm not personally bothered enough about this patch to fix it myself (I know that Jeremy has other approaches in pv_ops, which has to be what we move to during 3.4 development), so this is FYI if you want to fix it up for the 2.6.18 tree.

So you really think this will not only be available, but also stable and at feature parity with the current tree within about half a year? I've got other significant changes to event channel handling pending that I would only bother to make apply to 2.6.18 if there's really going to be any use (and testing) for them in that tree. They mostly have to do with the scalability issue of currently binding per-CPU IPIs and VIRQs to one (kernel) IRQ for each CPU, whereas they should really use a single per-CPU IRQ to bind all event channels resulting from the same IPI/VIRQ (Jeremy indicated he had something similar in mind for pv-ops).

Jan

****************************************************

Previously, the kernel depended upon Xen's NR_IRQS to be no larger than the kernel's NR_PIRQS.

As usual, written and tested on 2.6.27-rc5 and made apply to the 2.6.18 tree without further testing.

arch/i386/kernel/io_apic-xen.c +2 -1
Index: head-2008-09-01/arch/i386/kernel/io_apic-xen.c
===================================================================
@@ -52,6 +52,7 @@
 
 #include <xen/interface/xen.h>
 #include <xen/interface/physdev.h>
+#include <xen/evtchn.h>
 
 /* Fake i8259 */
 #define make_8259A_irq(_irq)     (io_apic_irqs &= ~(1UL<<(_irq)))
@@ -1275,7 +1276,7 @@ static void ioapic_register_intr(int irq
 	set_intr_gate(vector, interrupt[idx]);
 }
 #else
-#define ioapic_register_intr(_irq,_vector,_trigger) ((void)0)
+#define ioapic_register_intr(irq, vector, trigger) evtchn_register_pirq(irq)
 #endif
 
 static void __init setup_IO_APIC_irqs(void)
arch/x86_64/kernel/io_apic-xen.c +2 -1
Index: head-2008-09-01/arch/x86_64/kernel/io_apic-xen.c
===================================================================
@@ -81,6 +81,7 @@ int sis_apic_bug; /* not actually suppor
 
 #include <xen/interface/xen.h>
 #include <xen/interface/physdev.h>
+#include <xen/evtchn.h>
 
 /* Fake i8259 */
 #define make_8259A_irq(_irq)     (io_apic_irqs &= ~(1UL<<(_irq)))
@@ -840,7 +841,7 @@ static void ioapic_register_intr(int irq
 	set_intr_gate(vector, interrupt[idx]);
 }
 #else
-#define ioapic_register_intr(_irq,_vector,_trigger) ((void)0)
+#define ioapic_register_intr(irq, vector, trigger) evtchn_register_pirq(irq)
 #endif /* !CONFIG_XEN */
 
 static void __init setup_IO_APIC_irqs(void)
drivers/pci/msi-xen.c +11 -3
Index: head-2008-09-01/drivers/pci/msi-xen.c
===================================================================
@@ -17,6 +17,8 @@
 #include <linux/pci.h>
 #include <linux/proc_fs.h>
 
+#include <xen/evtchn.h>
+
 #include <asm/errno.h>
 #include <asm/io.h>
 #include <asm/smp.h>
@@ -231,13 +233,15 @@ static int msi_unmap_pirq(struct pci_dev
 	int rc;
 
 	unmap.domid = msi_get_dev_owner(dev);
-	unmap.pirq = pirq;
+	unmap.pirq = evtchn_get_xen_pirq(pirq);
 
 	if ((rc = HYPERVISOR_physdev_op(PHYSDEVOP_unmap_pirq, &unmap)))
 		printk(KERN_WARNING "unmap irq %x failed\n", pirq);
 
 	if (rc < 0)
 		return rc;
+
+	evtchn_map_pirq(pirq, 0);
 	return 0;
 }
 
@@ -272,7 +276,7 @@ static int msi_map_pirq_to_vector(struct
 	map_irq.domid = domid;
 	map_irq.type = MAP_PIRQ_TYPE_MSI;
 	map_irq.index = -1;
-	map_irq.pirq = pirq;
+	map_irq.pirq = pirq < 0 ? -1 : evtchn_get_xen_pirq(pirq);
 	map_irq.bus = dev->bus->number;
 	map_irq.devfn = dev->devfn;
 	map_irq.entry_nr = entry_nr;
@@ -283,8 +287,12 @@ static int msi_map_pirq_to_vector(struct
 
 	if (rc < 0)
 		return rc;
+	/* This happens when MSI support is not enabled in Xen. */
+	if (rc == 0 && map_irq.pirq < 0)
+		return -ENOSYS;
 
-	return map_irq.pirq;
+	BUG_ON(map_irq.pirq <= 0);
+	return evtchn_map_pirq(pirq, map_irq.pirq);
 }
 
 static int msi_map_vector(struct pci_dev *dev, int entry_nr, u64 table_base)
drivers/xen/core/evtchn.c +77 -9

141 lines not on this page · raw message

include/asm-i386/mach-xen/irq_vectors.h +7 -1
Index: head-2008-09-01/include/asm-i386/mach-xen/irq_vectors.h
===================================================================
@@ -37,7 +37,13 @@
  */
 
 #define PIRQ_BASE		0
-#define NR_PIRQS		256
+#if !defined(MAX_IO_APICS)
+# define NR_PIRQS		(NR_VECTORS + 32 * NR_CPUS)
+#elif NR_CPUS < MAX_IO_APICS
+# define NR_PIRQS		(NR_VECTORS + 32 * NR_CPUS)
+#else
+# define NR_PIRQS		(NR_VECTORS + 32 * MAX_IO_APICS)
+#endif
 
 #define DYNIRQ_BASE		(PIRQ_BASE + NR_PIRQS)
 #define NR_DYNIRQS		256
include/xen/evtchn.h +7 -0
Index: head-2008-09-01/include/xen/evtchn.h
===================================================================
@@ -117,6 +117,13 @@ asmlinkage void evtchn_do_upcall(struct 
 /* Entry point for notifications into the userland character device. */
 void evtchn_device_upcall(int port);
 
+/* Mark a PIRQ as unavailable for dynamic allocation. */
+void evtchn_register_pirq(int irq);
+/* Map a Xen-supplied PIRQ to a dynamically allocated one. */
+int evtchn_map_pirq(int irq, int xen_pirq);
+/* Look up a Xen-supplied PIRQ for a dynamically allocated one. */
+int evtchn_get_xen_pirq(int irq);
+
 void mask_evtchn(int port);
 void disable_all_local_evtchn(void);
 void unmask_evtchn(int port);
#3 lore raw
Quoted 5 lines · Jan Beulich
Quoted 4 lines

I'm not personally bothered enough about this patch to fix it myself (I know that Jeremy has other approaches in pv_ops, which has to be what we move to during 3.4 development), so this is FYI if you want to fix it up for the 2.6.18 tree.

Quoted 9 lines

So you really think this will not only be available, but also stable and at feature parity with the current tree within about half a year? I've got other significant changes to event channel handling pending that I would only bother to make apply to 2.6.18 if there's really going to be any use (and testing) for them in that tree. They mostly have to do with the scalability issue of currently binding per-CPU IPIs and VIRQs to one (kernel) IRQ for each CPU, whereas they should really use a single per-CPU IRQ to bind all event channels resulting from the same IPI/VIRQ (Jeremy indicated he had something similar in mind for pv-ops).

I believe we will be testing and running a xenbits pv_ops-based tree within 6 months, yes. Obviously we will have branches containing patches not yet in, or perhaps suitable for, upstream. Actually I hope we can move decisively towards this in the next couple of months, once Jeremy has the basic dom0 stuff working well enough.

-- Keir