Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch Fixes for physical interrupts on Xen:



details:   https://anonhg.NetBSD.org/src/rev/3259537eff9a
branches:  trunk
changeset: 828432:3259537eff9a
user:      bouyer <bouyer%NetBSD.org@localhost>
date:      Wed Dec 13 16:30:18 2017 +0000

description:
Fixes for physical interrupts on Xen:
- do not cast int * to intr_handle_t *, they're not the same size
- legacy_irq is not always -1 for ioapic interrupts, test pic_type instead
- change irq2port[] to hold (port + 1) so that 0 is an invalid value
- add KASSERTs to make sure vect, port or irq values extracted from arrays are
  valid (or that they are invalid before write)
- for the !ioapic case, we still need to do PHYSDEVOP_ASSIGN_VECTOR and
  bind_pirq_to_evtch().

now XEN3_DOM0 boots again

diffstat:

 sys/arch/x86/isa/isa_machdep.c |   8 ++++----
 sys/arch/x86/x86/intr.c        |  18 ++++++++++--------
 sys/arch/x86/x86/ioapic.c      |  10 ++++++----
 sys/arch/xen/include/intr.h    |   4 ++--
 sys/arch/xen/x86/pintr.c       |  28 +++++++++++++++++++++++-----
 sys/arch/xen/xen/evtchn.c      |   6 ++++--
 6 files changed, 49 insertions(+), 25 deletions(-)

diffs (253 lines):

diff -r 254eb084e13f -r 3259537eff9a sys/arch/x86/isa/isa_machdep.c
--- a/sys/arch/x86/isa/isa_machdep.c    Wed Dec 13 13:52:13 2017 +0000
+++ b/sys/arch/x86/isa/isa_machdep.c    Wed Dec 13 16:30:18 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: isa_machdep.c,v 1.37 2017/11/04 14:56:48 cherry Exp $  */
+/*     $NetBSD: isa_machdep.c,v 1.38 2017/12/13 16:30:18 bouyer Exp $  */
 
 /*-
  * Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc.
@@ -65,7 +65,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: isa_machdep.c,v 1.37 2017/11/04 14:56:48 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: isa_machdep.c,v 1.38 2017/12/13 16:30:18 bouyer Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -210,8 +210,8 @@
 {
        struct pic *pic;
        int pin;
+       intr_handle_t mpih = 0;
 #if NIOAPIC > 0
-       intr_handle_t mpih = 0;
        struct ioapic_softc *ioapic = NULL;
 #endif
 
@@ -245,7 +245,7 @@
 
        mpih |= APIC_IRQ_LEGACY_IRQ(irq);
 
-       evtch = xen_pirq_alloc((intr_handle_t *)&mpih, type); /* XXX: legacy - xen just tosses irq back at us */
+       evtch = xen_pirq_alloc(&mpih, type); /* XXX: legacy - xen just tosses irq back at us */
        if (evtch == -1)
                return NULL;
 #if NIOAPIC > 0
diff -r 254eb084e13f -r 3259537eff9a sys/arch/x86/x86/intr.c
--- a/sys/arch/x86/x86/intr.c   Wed Dec 13 13:52:13 2017 +0000
+++ b/sys/arch/x86/x86/intr.c   Wed Dec 13 16:30:18 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: intr.c,v 1.112 2017/11/11 21:05:58 riastradh Exp $     */
+/*     $NetBSD: intr.c,v 1.113 2017/12/13 16:30:18 bouyer Exp $        */
 
 /*-
  * Copyright (c) 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -133,7 +133,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.112 2017/11/11 21:05:58 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.113 2017/12/13 16:30:18 bouyer Exp $");
 
 #include "opt_intrdebug.h"
 #include "opt_multiprocessor.h"
@@ -1259,6 +1259,7 @@
 
 #if NPCI > 0 || NISA > 0
        struct pintrhand *pih;
+       intr_handle_t irq;
        int evtchn;
        char evname[16];
 
@@ -1267,12 +1268,12 @@
        KASSERTMSG(!(legacy_irq == -1 && pic == &i8259_pic),
            "non-legacy IRQon i8259 ");
 
-       if (legacy_irq == -1) {
+       if (pic->pic_type != PIC_I8259) {
 #if NIOAPIC > 0
                /* will do interrupts via I/O APIC */
-               legacy_irq = APIC_INT_VIA_APIC;
-               legacy_irq |= pic->pic_apicid << APIC_INT_APIC_SHIFT;
-               legacy_irq |= pin << APIC_INT_PIN_SHIFT;
+               irq = APIC_INT_VIA_APIC;
+               irq |= pic->pic_apicid << APIC_INT_APIC_SHIFT;
+               irq |= pin << APIC_INT_PIN_SHIFT;
                snprintf(evname, sizeof(evname), "%s pin %d",
                    pic->pic_name, pin);
 #else /* NIOAPIC */
@@ -1280,10 +1281,11 @@
 #endif /* NIOAPIC */
        } else {
                snprintf(evname, sizeof(evname), "irq%d", legacy_irq);
+               irq = legacy_irq;
        }
 
-       evtchn = xen_pirq_alloc((intr_handle_t *)&legacy_irq, type);
-       pih = pirq_establish(legacy_irq & 0xff, evtchn, handler, arg, level,
+       evtchn = xen_pirq_alloc(&irq, type);
+       pih = pirq_establish(irq & 0xff, evtchn, handler, arg, level,
            evname);
        pih->pic_type = pic->pic_type;
        return pih;
diff -r 254eb084e13f -r 3259537eff9a sys/arch/x86/x86/ioapic.c
--- a/sys/arch/x86/x86/ioapic.c Wed Dec 13 13:52:13 2017 +0000
+++ b/sys/arch/x86/x86/ioapic.c Wed Dec 13 16:30:18 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ioapic.c,v 1.55 2017/11/26 11:37:10 maxv Exp $ */
+/*     $NetBSD: ioapic.c,v 1.56 2017/12/13 16:30:18 bouyer Exp $       */
 
 /*-
  * Copyright (c) 2000, 2009 The NetBSD Foundation, Inc.
@@ -64,7 +64,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ioapic.c,v 1.55 2017/11/26 11:37:10 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ioapic.c,v 1.56 2017/12/13 16:30:18 bouyer Exp $");
 
 #include "opt_ddb.h"
 
@@ -575,10 +575,13 @@
 
        int port, irq;
        irq = vect2irq[idtvec];
+       KASSERT(irq != 0);
        port = bind_pirq_to_evtch(irq);
        KASSERT(port < NR_EVENT_CHANNELS);
+       KASSERT(port >= 0);
 
-       irq2port[irq] = port;
+       KASSERT(irq2port[irq] == 0);
+       irq2port[irq] = port + 1;
 
        xen_atomic_set_bit(&ci->ci_evtmask[0], port);
 #endif
@@ -595,7 +598,6 @@
 #if defined(XEN)
        int port, irq;
        irq = vect2irq[idtvec];
-       port = bind_pirq_to_evtch(irq);
        port = unbind_pirq_from_evtch(irq);
 
        KASSERT(port < NR_EVENT_CHANNELS);
diff -r 254eb084e13f -r 3259537eff9a sys/arch/xen/include/intr.h
--- a/sys/arch/xen/include/intr.h       Wed Dec 13 13:52:13 2017 +0000
+++ b/sys/arch/xen/include/intr.h       Wed Dec 13 16:30:18 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: intr.h,v 1.44 2017/11/04 14:56:48 cherry Exp $ */
+/*     $NetBSD: intr.h,v 1.45 2017/12/13 16:30:18 bouyer Exp $ */
 /*     NetBSD intr.h,v 1.15 2004/10/31 10:39:34 yamt Exp       */
 
 /*-
@@ -63,7 +63,7 @@
 extern struct intrstub xenev_stubs[];
 extern int irq2vect[256];
 extern int vect2irq[256];
-extern int irq2port[NR_EVENT_CHANNELS];
+extern int irq2port[NR_EVENT_CHANNELS]; /* actually port + 1, so that 0 is invaid */
 
 #ifdef MULTIPROCESSOR
 int xen_intr_biglock_wrapper(void *);
diff -r 254eb084e13f -r 3259537eff9a sys/arch/xen/x86/pintr.c
--- a/sys/arch/xen/x86/pintr.c  Wed Dec 13 13:52:13 2017 +0000
+++ b/sys/arch/xen/x86/pintr.c  Wed Dec 13 16:30:18 2017 +0000
@@ -103,7 +103,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pintr.c,v 1.1 2017/11/04 09:22:16 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pintr.c,v 1.2 2017/12/13 16:30:18 bouyer Exp $");
 
 #include "opt_multiprocessor.h"
 #include "opt_xen.h"
@@ -142,7 +142,7 @@
 struct intrstub x2apic_edge_stubs[MAX_INTR_SOURCES] = {{0,0}};
 struct intrstub x2apic_level_stubs[MAX_INTR_SOURCES] = {{0,0}};
 #include <machine/i82093var.h>
-int irq2port[NR_EVENT_CHANNELS] = {0};
+int irq2port[NR_EVENT_CHANNELS] = {0}; /* actually port + 1, so that 0 is invaid */
 int irq2vect[256] = {0};
 int vect2irq[256] = {0};
 #endif /* NIOAPIC */
@@ -162,6 +162,7 @@
 int
 xen_pirq_alloc(intr_handle_t *pirq, int type)
 {
+       physdev_op_t op;
        int irq = *pirq;
 #if NIOAPIC > 0
        extern struct cpu_info phycpu_info_primary; /* XXX */
@@ -180,7 +181,6 @@
        struct ioapic_softc *ioapic = ioapic_find(APIC_IRQ_APIC(*pirq));
        struct pic *pic = &ioapic->sc_pic;
        int pin = APIC_IRQ_PIN(*pirq);
-       physdev_op_t op;
 
        if (*pirq & APIC_INT_VIA_APIC) {
                irq = vect2irq[ioapic->sc_pins[pin].ip_vector];
@@ -199,15 +199,33 @@
                                        panic("PHYSDEVOP_ASSIGN_VECTOR irq %d", irq);
                                goto retry;
                        }
+                       KASSERT(irq2vect[irq] == 0);
                        irq2vect[irq] = op.u.irq_op.vector;
+                       KASSERT(vect2irq[op.u.irq_op.vector] == 0);
                        vect2irq[op.u.irq_op.vector] = irq;
                        pic->pic_addroute(pic, &phycpu_info_primary, pin,
                            op.u.irq_op.vector, type);
                }
                *pirq &= ~0xff;
                *pirq |= irq;
-       }
+       } else
 #endif /* NIOAPIC */
-       return irq2port[irq];
+       {
+               if (irq2port[irq] == 0) {
+                       op.cmd = PHYSDEVOP_ASSIGN_VECTOR;
+                       op.u.irq_op.irq = irq;
+                       if (HYPERVISOR_physdev_op(&op) < 0) {
+                               panic("PHYSDEVOP_ASSIGN_VECTOR irq %d", irq);
+                       }
+                       KASSERT(irq2vect[irq] == 0);
+                       irq2vect[irq] = op.u.irq_op.vector;
+                       KASSERT(vect2irq[op.u.irq_op.vector] == 0);
+                       vect2irq[op.u.irq_op.vector] = irq;
+                       KASSERT(irq2port[irq] == 0);
+                       irq2port[irq] = bind_pirq_to_evtch(irq) + 1;
+               }
+       }
+       KASSERT(irq2port[irq] > 0);
+       return (irq2port[irq] - 1);
 }
 #endif /* defined(DOM0OPS) || NPCI > 0 */
diff -r 254eb084e13f -r 3259537eff9a sys/arch/xen/xen/evtchn.c
--- a/sys/arch/xen/xen/evtchn.c Wed Dec 13 13:52:13 2017 +0000
+++ b/sys/arch/xen/xen/evtchn.c Wed Dec 13 16:30:18 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: evtchn.c,v 1.78 2017/11/11 17:02:53 riastradh Exp $    */
+/*     $NetBSD: evtchn.c,v 1.79 2017/12/13 16:30:18 bouyer Exp $       */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -54,7 +54,7 @@
 
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: evtchn.c,v 1.78 2017/11/11 17:02:53 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: evtchn.c,v 1.79 2017/12/13 16:30:18 bouyer Exp $");
 
 #include "opt_xen.h"
 #include "isa.h"
@@ -745,6 +745,8 @@
                return NULL;
        }
 
+       KASSERT(evtch > 0);
+
        ih->pirq = pirq;
        ih->evtch = evtch;
        ih->func = func;



Home | Main Index | Thread Index | Old Index