Module Name: src
Committed By: bouyer
Date: Wed Dec 13 16:30:18 UTC 2017
Modified Files:
src/sys/arch/x86/isa: isa_machdep.c
src/sys/arch/x86/x86: intr.c ioapic.c
src/sys/arch/xen/include: intr.h
src/sys/arch/xen/x86: pintr.c
src/sys/arch/xen/xen: evtchn.c
Log Message:
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
To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.38 src/sys/arch/x86/isa/isa_machdep.c
cvs rdiff -u -r1.112 -r1.113 src/sys/arch/x86/x86/intr.c
cvs rdiff -u -r1.55 -r1.56 src/sys/arch/x86/x86/ioapic.c
cvs rdiff -u -r1.44 -r1.45 src/sys/arch/xen/include/intr.h
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/xen/x86/pintr.c
cvs rdiff -u -r1.78 -r1.79 src/sys/arch/xen/xen/evtchn.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/arch/x86/isa/isa_machdep.c
diff -u src/sys/arch/x86/isa/isa_machdep.c:1.37 src/sys/arch/x86/isa/isa_machdep.c:1.38
--- src/sys/arch/x86/isa/isa_machdep.c:1.37 Sat Nov 4 14:56:48 2017
+++ src/sys/arch/x86/isa/isa_machdep.c Wed Dec 13 16:30:18 2017
@@ -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 @@ isa_intr_establish_xname(isa_chipset_tag
{
struct pic *pic;
int pin;
-#if NIOAPIC > 0
intr_handle_t mpih = 0;
+#if NIOAPIC > 0
struct ioapic_softc *ioapic = NULL;
#endif
@@ -245,7 +245,7 @@ isa_intr_establish_xname(isa_chipset_tag
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
Index: src/sys/arch/x86/x86/intr.c
diff -u src/sys/arch/x86/x86/intr.c:1.112 src/sys/arch/x86/x86/intr.c:1.113
--- src/sys/arch/x86/x86/intr.c:1.112 Sat Nov 11 21:05:58 2017
+++ src/sys/arch/x86/x86/intr.c Wed Dec 13 16:30:18 2017
@@ -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 @@ intr_establish_xname(int legacy_irq, str
#if NPCI > 0 || NISA > 0
struct pintrhand *pih;
+ intr_handle_t irq;
int evtchn;
char evname[16];
@@ -1267,12 +1268,12 @@ intr_establish_xname(int legacy_irq, str
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 @@ intr_establish_xname(int legacy_irq, str
#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;
Index: src/sys/arch/x86/x86/ioapic.c
diff -u src/sys/arch/x86/x86/ioapic.c:1.55 src/sys/arch/x86/x86/ioapic.c:1.56
--- src/sys/arch/x86/x86/ioapic.c:1.55 Sun Nov 26 11:37:10 2017
+++ src/sys/arch/x86/x86/ioapic.c Wed Dec 13 16:30:18 2017
@@ -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 @@ ioapic_addroute(struct pic *pic, struct
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 @@ ioapic_delroute(struct pic *pic, struct
#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);
Index: src/sys/arch/xen/include/intr.h
diff -u src/sys/arch/xen/include/intr.h:1.44 src/sys/arch/xen/include/intr.h:1.45
--- src/sys/arch/xen/include/intr.h:1.44 Sat Nov 4 14:56:48 2017
+++ src/sys/arch/xen/include/intr.h Wed Dec 13 16:30:18 2017
@@ -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 @@ struct evtsource {
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 *);
Index: src/sys/arch/xen/x86/pintr.c
diff -u src/sys/arch/xen/x86/pintr.c:1.1 src/sys/arch/xen/x86/pintr.c:1.2
--- src/sys/arch/xen/x86/pintr.c:1.1 Sat Nov 4 09:22:16 2017
+++ src/sys/arch/xen/x86/pintr.c Wed Dec 13 16:30:18 2017
@@ -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 ioapic_level_stubs[MAX_I
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 vect2irq[256] = {0};
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 @@ xen_pirq_alloc(intr_handle_t *pirq, int
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 @@ retry:
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 */
Index: src/sys/arch/xen/xen/evtchn.c
diff -u src/sys/arch/xen/xen/evtchn.c:1.78 src/sys/arch/xen/xen/evtchn.c:1.79
--- src/sys/arch/xen/xen/evtchn.c:1.78 Sat Nov 11 17:02:53 2017
+++ src/sys/arch/xen/xen/evtchn.c Wed Dec 13 16:30:18 2017
@@ -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 @@ pirq_establish(int pirq, int evtch, int
return NULL;
}
+ KASSERT(evtch > 0);
+
ih->pirq = pirq;
ih->evtch = evtch;
ih->func = func;