Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/x86/x86 Clean up XEN specific stuff from the apic c...



details:   https://anonhg.NetBSD.org/src/rev/2a4643c4b744
branches:  trunk
changeset: 836286:2a4643c4b744
user:      cherry <cherry%NetBSD.org@localhost>
date:      Mon Oct 08 08:05:08 2018 +0000

description:
Clean up XEN specific stuff from the apic code, and move to intr.c

No functional change.

diffstat:

 sys/arch/x86/x86/i8259.c  |  62 ++--------------------------------------------
 sys/arch/x86/x86/intr.c   |  52 +++++++++++++++++++++++++++++++++------
 sys/arch/x86/x86/ioapic.c |  51 +-------------------------------------
 3 files changed, 49 insertions(+), 116 deletions(-)

diffs (268 lines):

diff -r 5670188d53ca -r 2a4643c4b744 sys/arch/x86/x86/i8259.c
--- a/sys/arch/x86/x86/i8259.c  Mon Oct 08 05:42:44 2018 +0000
+++ b/sys/arch/x86/x86/i8259.c  Mon Oct 08 08:05:08 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: i8259.c,v 1.20 2018/10/07 16:36:36 cherry Exp $        */
+/*     $NetBSD: i8259.c,v 1.21 2018/10/08 08:05:08 cherry Exp $        */
 
 /*
  * Copyright 2002 (c) Wasabi Systems, Inc.
@@ -70,7 +70,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: i8259.c,v 1.20 2018/10/07 16:36:36 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: i8259.c,v 1.21 2018/10/08 08:05:08 cherry Exp $");
 
 #include <sys/param.h> 
 #include <sys/systm.h>
@@ -88,9 +88,6 @@
 #include <machine/pic.h>
 #include <machine/i8259.h>
 
-#ifdef XEN
-#include <xen/evtchn.h>
-#endif
 
 #ifndef __x86_64__
 #include "mca.h"
@@ -102,7 +99,6 @@
 static void i8259_hwmask(struct pic *, int);
 static void i8259_hwunmask(struct pic *, int);
 static void i8259_setup(struct pic *, struct cpu_info *, int, int, int);
-static void i8259_unsetup(struct pic *, struct cpu_info *, int, int, int);
 static void i8259_reinit_irqs(void);
 
 unsigned i8259_imen;
@@ -119,7 +115,7 @@
        .pic_hwmask = i8259_hwmask,
        .pic_hwunmask = i8259_hwunmask,
        .pic_addroute = i8259_setup,
-       .pic_delroute = i8259_unsetup,
+       .pic_delroute = i8259_setup,
        .pic_level_stubs = legacy_stubs,
        .pic_edge_stubs = legacy_stubs,
 };
@@ -256,62 +252,10 @@
 i8259_setup(struct pic *pic, struct cpu_info *ci,
     int pin, int idtvec, int type)
 {
-#if defined(XEN)
-       /*
-        * This is kludgy, and not the right place, but we can't bind
-        * before the routing has been set to the appropriate 'vector'.
-        * in x86/intr.c, this is done after idt_vec_set(), where this
-        * would have been more appropriate to put this.
-        */
-
-       int port, irq;
-       irq = vect2irq[idtvec];
-       KASSERT(irq != 0);
-       if (irq2port[irq] != 0) {
-               /* 
-                * Shared interrupt - we can't rebind.
-                *  The port is shared instead.
-                */
-               return;
-       }
-       
-       port = bind_pirq_to_evtch(irq);
-       KASSERT(port < NR_EVENT_CHANNELS);
-       KASSERT(port >= 0);
-
-       KASSERT(irq2port[irq] == 0);
-       irq2port[irq] = port + 1;
-
-       xen_atomic_set_bit(&ci->ci_evtmask[0], port);
-#else
        if (CPU_IS_PRIMARY(ci))
                i8259_reinit_irqs();
-#endif
 }
 
-static void
-i8259_unsetup(struct pic *pic, struct cpu_info *ci,
-    int pin, int idtvec, int type)
-{
-#if defined(XEN)
-       int port, irq;
-       irq = vect2irq[idtvec];
-       port = unbind_pirq_from_evtch(irq);
-
-       KASSERT(port < NR_EVENT_CHANNELS);
-
-       /* XXX: This is problematic for shared interrupts */
-       KASSERT(irq2port[irq] != 0);
-       irq2port[irq] = 0;
-
-       xen_atomic_clear_bit(&ci->ci_evtmask[0], port);
-#else
-       if (CPU_IS_PRIMARY(ci))
-               i8259_reinit_irqs();
-#endif
-}
-
-
 void
 i8259_reinit(void)
 {
diff -r 5670188d53ca -r 2a4643c4b744 sys/arch/x86/x86/intr.c
--- a/sys/arch/x86/x86/intr.c   Mon Oct 08 05:42:44 2018 +0000
+++ b/sys/arch/x86/x86/intr.c   Mon Oct 08 08:05:08 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: intr.c,v 1.133 2018/10/07 05:23:01 cherry Exp $        */
+/*     $NetBSD: intr.c,v 1.134 2018/10/08 08:05:08 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.133 2018/10/07 05:23:01 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.134 2018/10/08 08:05:08 cherry Exp $");
 
 #include "opt_intrdebug.h"
 #include "opt_multiprocessor.h"
@@ -1278,12 +1278,24 @@
 
        vector = xen_vec_alloc(gsi);
 
-       extern struct cpu_info phycpu_info_primary; /* XXX */
-       struct cpu_info *ci = &phycpu_info_primary;
-       pic->pic_addroute(pic, ci, pin, vector, type);
+       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 = irq2port[vect2irq[vector]];
-       KASSERT(evtchn > 0);
+               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];
+       }
 
        pih = pirq_establish(gsi, evtchn, handler, arg, level,
                             intrstr, xname);
@@ -1337,7 +1349,31 @@
                return;
        }
 #if defined(DOM0OPS)
-       pirq_disestablish((struct pintrhand *)ih);
+       /* 
+        * 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 */
diff -r 5670188d53ca -r 2a4643c4b744 sys/arch/x86/x86/ioapic.c
--- a/sys/arch/x86/x86/ioapic.c Mon Oct 08 05:42:44 2018 +0000
+++ b/sys/arch/x86/x86/ioapic.c Mon Oct 08 08:05:08 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ioapic.c,v 1.58 2018/10/07 16:36:36 cherry Exp $       */
+/*     $NetBSD: ioapic.c,v 1.59 2018/10/08 08:05:08 cherry 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.58 2018/10/07 16:36:36 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ioapic.c,v 1.59 2018/10/08 08:05:08 cherry Exp $");
 
 #include "opt_ddb.h"
 
@@ -564,37 +564,6 @@
        pp->ip_vector = idtvec;
        pp->ip_cpu = ci;
        apic_set_redir(sc, pin, idtvec, ci);
-
-#if defined(XEN)
-       /*
-        * This is kludgy, and not the right place, but we can't bind
-        * before the routing has been set to the appropriate 'vector'.
-        * in x86/intr.c, this is done after idt_vec_set(), where this
-        * would have been more appropriate to put this.
-        */
-
-       int port, irq;
-       irq = vect2irq[idtvec];
-       KASSERT(irq != 0);
-
-       if (irq2port[irq] != 0) {
-               /* 
-                * Shared interrupt - we can't rebind.
-                *  The port is shared instead.
-                */
-               return;
-       }
-
-       port = bind_pirq_to_evtch(irq);
-       KASSERT(port < NR_EVENT_CHANNELS);
-       KASSERT(port >= 0);
-
-       KASSERT(irq2port[irq] == 0);
-       irq2port[irq] = port + 1;
-
-       xen_atomic_set_bit(&ci->ci_evtmask[0], port);
-#endif
-
 }
 
 static void
@@ -603,22 +572,6 @@
 {
 
        ioapic_hwmask(pic, pin);
-
-#if defined(XEN)
-       int port, irq;
-       irq = vect2irq[idtvec];
-       port = unbind_pirq_from_evtch(irq);
-
-       KASSERT(port < NR_EVENT_CHANNELS);
-
-       /* XXX: This is problematic for shared interrupts */
-       KASSERT(irq2port[irq] != 0);
-       irq2port[irq] = 0;
-
-       xen_atomic_clear_bit(&ci->ci_evtmask[0], port);
-
-#endif
-
 }
 
 #ifdef DDB



Home | Main Index | Thread Index | Old Index