Source-Changes-HG archive

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

[src/trunk]: src/sys/arch Bifurcate the interrupt establish functions between...



details:   https://anonhg.NetBSD.org/src/rev/8edf6d2f16fa
branches:  trunk
changeset: 995471:8edf6d2f16fa
user:      cherry <cherry%NetBSD.org@localhost>
date:      Mon Dec 24 14:55:41 2018 +0000

description:
Bifurcate the interrupt establish functions between XEN and non-XEN

Thus intr_establish_xname() becomes xen_intr_establish_xname() etc.

One consequence of this is that dom0 devices expect the native
function calls to be available and we thus provide weak aliasing for
dom0 builds to succeed. XEN and non-XEN devices are distinguished by
the PIC they are established on. XEN interrupts are exclusively
established on xen_pic, while dom0 interrupts are established on
natively available PICs.

This allows us an orthogonal path to xen device management (eg:
xenstore events) in XENPVHVM, without having to worry about unifying
the vector entry paths, etc., which is quite challenging.

diffstat:

 sys/arch/x86/x86/intr.c              |  147 +--------------------------------
 sys/arch/xen/include/intr.h          |    9 +-
 sys/arch/xen/x86/xen_intr.c          |  156 ++++++++++++++++++++++++++++++++++-
 sys/arch/xen/x86/xen_ipi.c           |    8 +-
 sys/arch/xen/xen/clock.c             |    8 +-
 sys/arch/xen/xen/if_xennet_xenbus.c  |   10 +-
 sys/arch/xen/xen/pciback.c           |   10 +-
 sys/arch/xen/xen/xbd_xenbus.c        |   10 +-
 sys/arch/xen/xen/xbdback_xenbus.c    |    8 +-
 sys/arch/xen/xen/xencons.c           |   10 +-
 sys/arch/xen/xen/xenevt.c            |    8 +-
 sys/arch/xen/xen/xennetback_xenbus.c |    8 +-
 sys/arch/xen/xen/xpci_xenbus.c       |    6 +-
 sys/arch/xen/xenbus/xenbus_comms.c   |    8 +-
 14 files changed, 213 insertions(+), 193 deletions(-)

diffs (truncated from 789 to 300 lines):

diff -r ce25875d819a -r 8edf6d2f16fa sys/arch/x86/x86/intr.c
--- a/sys/arch/x86/x86/intr.c   Mon Dec 24 13:31:22 2018 +0000
+++ b/sys/arch/x86/x86/intr.c   Mon Dec 24 14:55:41 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: intr.c,v 1.138 2018/12/23 12:11:40 jdolecek Exp $      */
+/*     $NetBSD: intr.c,v 1.139 2018/12/24 14:55:41 cherry 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.138 2018/12/23 12:11:40 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.139 2018/12/24 14:55:41 cherry Exp $");
 
 #include "opt_intrdebug.h"
 #include "opt_multiprocessor.h"
@@ -1207,117 +1207,12 @@
        return num;
 }
 
-#else /* XEN */
-void *
-intr_establish(int legacy_irq, struct pic *pic, int pin,
-    int type, int level, int (*handler)(void *), void *arg,
-    bool known_mpsafe)
-{
-
-       return intr_establish_xname(legacy_irq, pic, pin, type, level,
-           handler, arg, known_mpsafe, "XEN");
-}
-
-void *
-intr_establish_xname(int legacy_irq, struct pic *pic, int pin,
-    int type, int level, int (*handler)(void *), void *arg,
-    bool known_mpsafe, const char *xname)
-{
-       const char *intrstr;
-       char intrstr_buf[INTRIDBUF];
-
-       if (pic->pic_type == PIC_XEN) {
-               struct intrhand *rih;
-
-               /*
-                * event_set_handler interprets `level != IPL_VM' to
-                * mean MP-safe, so we require the caller to match that
-                * for the moment.
-                */
-               KASSERT(known_mpsafe == (level != IPL_VM));
-
-               intrstr = intr_create_intrid(legacy_irq, pic, pin, intrstr_buf,
-                   sizeof(intrstr_buf));
-
-               event_set_handler(pin, handler, arg, level, intrstr, xname);
-
-               rih = kmem_zalloc(sizeof(*rih), cold ? KM_NOSLEEP : KM_SLEEP);
-               if (rih == NULL) {
-                       printf("%s: can't allocate handler info\n", __func__);
-                       return NULL;
-               }
-
-               /*
-                * XXX:
-                * This is just a copy for API conformance.
-                * The real ih is lost in the innards of
-                * event_set_handler(); where the details of
-                * biglock_wrapper etc are taken care of.
-                * All that goes away when we nuke event_set_handler()
-                * et. al. and unify with x86/intr.c
-                */
-               rih->ih_pin = pin; /* port */
-               rih->ih_fun = rih->ih_realfun = handler;
-               rih->ih_arg = rih->ih_realarg = arg;
-               rih->pic_type = pic->pic_type;
-               return rih;
-       }       /* Else we assume pintr */
-
-#if NPCI > 0 || NISA > 0
-       struct pintrhand *pih;
-       int gsi;
-       int vector, evtchn;
-
-       KASSERTMSG(legacy_irq == -1 || (0 <= legacy_irq && legacy_irq < NUM_XEN_IRQS),
-           "bad legacy IRQ value: %d", legacy_irq);
-       KASSERTMSG(!(legacy_irq == -1 && pic == &i8259_pic),
-           "non-legacy IRQon i8259 ");
-
-       gsi = xen_pic_to_gsi(pic, pin);
-
-       intrstr = intr_create_intrid(gsi, pic, pin, intrstr_buf,
-           sizeof(intrstr_buf));
-
-       vector = xen_vec_alloc(gsi);
-
-       if (irq2port[gsi] == 0) {
-               extern struct cpu_info phycpu_info_primary; /* XXX */
-               struct cpu_info *ci = &phycpu_info_primary;
-
-               pic->pic_addroute(pic, ci, pin, vector, type);
-
-               evtchn = bind_pirq_to_evtch(gsi);
-               KASSERT(evtchn > 0);
-               KASSERT(evtchn < NR_EVENT_CHANNELS);
-               irq2port[gsi] = evtchn + 1;
-               xen_atomic_set_bit(&ci->ci_evtmask[0], evtchn);
-       } else {
-               /*
-                * Shared interrupt - we can't rebind.
-                * The port is shared instead.
-                */
-               evtchn = irq2port[gsi] - 1;
-       }
-
-       pih = pirq_establish(gsi, evtchn, handler, arg, level,
-                            intrstr, xname);
-       pih->pic_type = pic->pic_type;
-       return pih;
-#endif /* NPCI > 0 || NISA > 0 */
-
-       /* FALLTHROUGH */
-       return NULL;
-}
-
-#endif /* XEN */
-
 /*
  * Deregister an interrupt handler.
  */
 void
 intr_disestablish(struct intrhand *ih)
 {
-#if !defined(XEN)
        struct cpu_info *ci;
        struct intrsource *isp;
        uint64_t where;
@@ -1343,43 +1238,9 @@
        }
        mutex_exit(&cpu_lock);
        kmem_free(ih, sizeof(*ih));
-#else /* XEN */
-       if (ih->pic_type == PIC_XEN) {
-               event_remove_handler(ih->ih_pin, ih->ih_realfun,
-                   ih->ih_realarg);
-               kmem_free(ih, sizeof(*ih));
-               return;
-       }
-#if defined(DOM0OPS)
-       /* 
-        * Cache state, to prevent a use after free situation with
-        * ih.
-        */
-
-       struct pintrhand *pih = (struct pintrhand *)ih;
-
-       int pirq = pih->pirq;
-       int port = pih->evtch;
-       KASSERT(irq2port[pirq] != 0);
+}
 
-       pirq_disestablish(pih);
-
-       if (evtsource[port] == NULL) {
-                       /*
-                        * Last handler was removed by
-                        * event_remove_handler().
-                        *
-                        * We can safely unbind the pirq now.
-                        */
-
-                       port = unbind_pirq_from_evtch(pirq);
-                       KASSERT(port == pih->evtch);
-                       irq2port[pirq] = 0;
-       }
-#endif
-       return;
-#endif /* XEN */
-}
+#endif /* !XEN */
 
 #if defined(XEN) /* nuke conditional post integration */
 static const char *
diff -r ce25875d819a -r 8edf6d2f16fa sys/arch/xen/include/intr.h
--- a/sys/arch/xen/include/intr.h       Mon Dec 24 13:31:22 2018 +0000
+++ b/sys/arch/xen/include/intr.h       Mon Dec 24 14:55:41 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: intr.h,v 1.49 2018/10/10 02:34:08 cherry Exp $ */
+/*     $NetBSD: intr.h,v 1.50 2018/12/24 14:55:42 cherry Exp $ */
 /*     NetBSD intr.h,v 1.15 2004/10/31 10:39:34 yamt Exp       */
 
 /*-
@@ -82,6 +82,13 @@
 #define xen_send_ipi(_i1, _i2) (0) /* nothing */
 #define xen_broadcast_ipi(_i1) ((void) 0) /* nothing */
 #endif /* MULTIPROCESSOR */
+
+void *xen_intr_establish_xname(int, struct pic *, int, int, int, int (*)(void *),
+    void *, bool, const char *);
+void *xen_intr_establish(int, struct pic *, int, int, int, int (*)(void *),
+    void *, bool);
+void xen_intr_disestablish(struct intrhand *);
+
 #endif /* !_LOCORE */
 
 #endif /* _XEN_INTR_H_ */
diff -r ce25875d819a -r 8edf6d2f16fa sys/arch/xen/x86/xen_intr.c
--- a/sys/arch/xen/x86/xen_intr.c       Mon Dec 24 13:31:22 2018 +0000
+++ b/sys/arch/xen/x86/xen_intr.c       Mon Dec 24 14:55:41 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: xen_intr.c,v 1.9 2009/01/16 20:16:47 jym Exp $ */
+/*     $NetBSD: xen_intr.c,v 1.10 2018/12/24 14:55:42 cherry Exp $     */
 
 /*-
  * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
@@ -30,9 +30,13 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: xen_intr.c,v 1.9 2009/01/16 20:16:47 jym Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xen_intr.c,v 1.10 2018/12/24 14:55:42 cherry Exp $");
 
 #include <sys/param.h>
+#include <sys/kernel.h>
+#include <sys/kmem.h>
+
+#include <xen/evtchn.h>
 
 #include <machine/cpu.h>
 #include <machine/intr.h>
@@ -112,3 +116,151 @@
                hypervisor_force_callback();
        }
 }
+
+void *
+xen_intr_establish(int legacy_irq, struct pic *pic, int pin,
+    int type, int level, int (*handler)(void *), void *arg,
+    bool known_mpsafe)
+{
+
+       return xen_intr_establish_xname(legacy_irq, pic, pin, type, level,
+           handler, arg, known_mpsafe, "XEN");
+}
+
+void *
+xen_intr_establish_xname(int legacy_irq, struct pic *pic, int pin,
+    int type, int level, int (*handler)(void *), void *arg,
+    bool known_mpsafe, const char *xname)
+{
+       const char *intrstr;
+       char intrstr_buf[INTRIDBUF];
+
+       if (pic->pic_type == PIC_XEN) {
+               struct intrhand *rih;
+
+               /*
+                * event_set_handler interprets `level != IPL_VM' to
+                * mean MP-safe, so we require the caller to match that
+                * for the moment.
+                */
+               KASSERT(known_mpsafe == (level != IPL_VM));
+
+               intrstr = intr_create_intrid(legacy_irq, pic, pin, intrstr_buf,
+                   sizeof(intrstr_buf));
+
+               event_set_handler(pin, handler, arg, level, intrstr, xname);
+
+               rih = kmem_zalloc(sizeof(*rih), cold ? KM_NOSLEEP : KM_SLEEP);
+               if (rih == NULL) {
+                       printf("%s: can't allocate handler info\n", __func__);
+                       return NULL;
+               }
+
+               /*
+                * XXX:
+                * This is just a copy for API conformance.
+                * The real ih is lost in the innards of
+                * event_set_handler(); where the details of
+                * biglock_wrapper etc are taken care of.
+                * All that goes away when we nuke event_set_handler()
+                * et. al. and unify with x86/intr.c
+                */
+               rih->ih_pin = pin; /* port */
+               rih->ih_fun = rih->ih_realfun = handler;
+               rih->ih_arg = rih->ih_realarg = arg;
+               rih->pic_type = pic->pic_type;
+               return rih;
+       }       /* Else we assume pintr */
+
+#if NPCI > 0 || NISA > 0
+       struct pintrhand *pih;
+       int gsi;
+       int vector, evtchn;
+
+       KASSERTMSG(legacy_irq == -1 || (0 <= legacy_irq && legacy_irq < NUM_XEN_IRQS),
+           "bad legacy IRQ value: %d", legacy_irq);
+       KASSERTMSG(!(legacy_irq == -1 && pic == &i8259_pic),
+           "non-legacy IRQon i8259 ");
+
+       gsi = xen_pic_to_gsi(pic, pin);



Home | Main Index | Thread Index | Old Index