Use intr_enable()/int_disable()/intr_restore() instead of
authorkettenis <kettenis@openbsd.org>
Sat, 15 May 2021 11:30:27 +0000 (11:30 +0000)
committerkettenis <kettenis@openbsd.org>
Sat, 15 May 2021 11:30:27 +0000 (11:30 +0000)
enable_interrupts()/disable_interrupts()/restore_interrupts() and remove
the latter interfaces.

While there move a few malloc(9) and free(9) calls to run with interrupts
enabled.

ok patrick@

sys/arch/arm64/arm64/intr.c
sys/arch/arm64/arm64/syscall.c
sys/arch/arm64/arm64/trap.c
sys/arch/arm64/arm64/vfp.c
sys/arch/arm64/dev/agintc.c
sys/arch/arm64/dev/ampintc.c
sys/arch/arm64/dev/bcm2836_intr.c
sys/arch/arm64/dev/efi.c
sys/arch/arm64/include/cpu.h

index bca105b..bdd79a3 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: intr.c,v 1.21 2021/03/11 11:16:55 jsg Exp $ */
+/* $OpenBSD: intr.c,v 1.22 2021/05/15 11:30:27 kettenis Exp $ */
 /*
  * Copyright (c) 2011 Dale Rahn <drahn@openbsd.org>
  *
@@ -665,18 +665,18 @@ void
 arm_do_pending_intr(int pcpl)
 {
        struct cpu_info *ci = curcpu();
-       int oldirqstate;
+       u_long oldirqstate;
 
-       oldirqstate = disable_interrupts();
+       oldirqstate = intr_disable();
 
 #define DO_SOFTINT(si, ipl) \
        if ((ci->ci_ipending & arm_smask[pcpl]) &       \
-           SI_TO_IRQBIT(si)) {                                         \
-               ci->ci_ipending &= ~SI_TO_IRQBIT(si);                   \
-               arm_intr_func.setipl(ipl);                              \
-               restore_interrupts(oldirqstate);                        \
-               softintr_dispatch(si);                                  \
-               oldirqstate = disable_interrupts();                     \
+           SI_TO_IRQBIT(si)) {                         \
+               ci->ci_ipending &= ~SI_TO_IRQBIT(si);   \
+               arm_intr_func.setipl(ipl);              \
+               intr_restore(oldirqstate);              \
+               softintr_dispatch(si);                  \
+               oldirqstate = intr_disable();           \
        }
 
        do {
@@ -688,7 +688,7 @@ arm_do_pending_intr(int pcpl)
 
        /* Don't use splx... we are here already! */
        arm_intr_func.setipl(pcpl);
-       restore_interrupts(oldirqstate);
+       intr_restore(oldirqstate);
 }
 
 void
index af40a48..0154eea 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: syscall.c,v 1.6 2020/03/13 05:20:07 deraadt Exp $ */
+/* $OpenBSD: syscall.c,v 1.7 2021/05/15 11:30:27 kettenis Exp $ */
 /*
  * Copyright (c) 2015 Dale Rahn <drahn@dalerahn.com>
  *
@@ -48,7 +48,7 @@ svc_handler(trapframe_t *frame)
 
        /* Re-enable interrupts if they were enabled previously */
        if (__predict_true((frame->tf_spsr & I_bit) == 0))
-               enable_interrupts();
+               intr_enable();
 
        /* Skip over speculation-blocking barrier. */
        frame->tf_elr += 8;
index c4a3ef0..4e7e8cc 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: trap.c,v 1.36 2021/05/05 07:29:00 mpi Exp $ */
+/* $OpenBSD: trap.c,v 1.37 2021/05/15 11:30:27 kettenis Exp $ */
 /*-
  * Copyright (c) 2014 Andrew Turner
  * All rights reserved.
@@ -204,7 +204,7 @@ do_el1h_sync(struct trapframe *frame)
        exception = ESR_ELx_EXCEPTION(esr);
        far = READ_SPECIALREG(far_el1);
 
-       enable_interrupts();
+       intr_enable();
 
        /*
         * Sanity check we are in an exception er can handle. The IL bit
@@ -266,7 +266,7 @@ do_el0_sync(struct trapframe *frame)
        exception = ESR_ELx_EXCEPTION(esr);
        far = READ_SPECIALREG(far_el1);
 
-       enable_interrupts();
+       intr_enable();
 
        p->p_addr->u_pcb.pcb_tf = frame;
        refreshcreds(p);
index 2906d63..4518dbf 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: vfp.c,v 1.4 2018/07/02 07:23:37 kettenis Exp $ */
+/* $OpenBSD: vfp.c,v 1.5 2021/05/15 11:30:27 kettenis Exp $ */
 /*
  * Copyright (c) 2011 Dale Rahn <drahn@openbsd.org>
  *
@@ -142,7 +142,7 @@ vfp_enable(void)
 
        if (curproc->p_addr->u_pcb.pcb_fpcpu == ci &&
            ci->ci_fpuproc == curproc) {
-               disable_interrupts();
+               intr_disable();
 
                /* FPU state is still valid, just enable and go */
                set_vfp_enable(1);
@@ -155,10 +155,10 @@ vfp_load(struct proc *p)
        struct cpu_info *ci = curcpu();
        struct pcb *pcb = &p->p_addr->u_pcb;
        uint32_t scratch = 0;
-       int psw;
+       u_long psw;
 
        /* do not allow a partially synced state here */
-       psw = disable_interrupts();
+       psw = intr_disable();
 
        /*
         * p->p_pcb->pcb_fpucpu _may_ not be NULL here, but the FPU state
@@ -215,7 +215,7 @@ vfp_load(struct proc *p)
        /* disable until return to userland */
        set_vfp_enable(0);
 
-       restore_interrupts(psw);
+       intr_restore(psw);
 }
 
 
index 60b6aa4..9cbe942 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: agintc.c,v 1.31 2021/05/05 12:02:21 kettenis Exp $ */
+/* $OpenBSD: agintc.c,v 1.32 2021/05/15 11:30:27 kettenis Exp $ */
 /*
  * Copyright (c) 2007, 2009, 2011, 2017 Dale Rahn <drahn@dalerahn.com>
  * Copyright (c) 2018 Mark Kettenis <kettenis@openbsd.org>
@@ -275,19 +275,19 @@ agintc_attach(struct device *parent, struct device *self, void *aux)
        struct fdt_attach_args  *faa = aux;
        struct cpu_info         *ci;
        CPU_INFO_ITERATOR        cii;
+       u_long                   psw;
        uint32_t                 typer;
        uint32_t                 nsacr, oldnsacr;
        uint32_t                 pmr, oldpmr;
        uint32_t                 ctrl, bits;
        uint32_t                 affinity;
        int                      i, nbits, nintr;
-       int                      psw;
        int                      offset, nredist;
 #ifdef MULTIPROCESSOR
        int                      nipi, ipiirq[2];
 #endif
 
-       psw = disable_interrupts();
+       psw = intr_disable();
        arm_init_smask();
 
        sc->sc_iot = faa->fa_iot;
@@ -604,7 +604,7 @@ agintc_attach(struct device *parent, struct device *self, void *aux)
        sc->sc_ic.ic_barrier = agintc_intr_barrier;
        arm_intr_register_fdt(&sc->sc_ic);
 
-       restore_interrupts(psw);
+       intr_restore(psw);
 
        /* Attach ITS. */
        simplebus_attach(parent, &sc->sc_sbus.sc_dev, faa);
@@ -673,7 +673,7 @@ agintc_cpuinit(void)
        __asm volatile("msr "STR(ICC_PMR)", %x0" :: "r"(0xff));
        __asm volatile("msr "STR(ICC_BPR1)", %x0" :: "r"(0));
        __asm volatile("msr "STR(ICC_IGRPEN1)", %x0" :: "r"(1));
-       enable_interrupts();
+       intr_enable();
 }
 
 void
@@ -700,18 +700,18 @@ agintc_setipl(int ipl)
 {
        struct agintc_softc     *sc = agintc_sc;
        struct cpu_info         *ci = curcpu();
-       int                      psw;
+       u_long                   psw;
        uint32_t                 prival;
 
        /* disable here is only to keep hardware in sync with ci->ci_cpl */
-       psw = disable_interrupts();
+       psw = intr_disable();
        ci->ci_cpl = ipl;
 
        prival = ((0xff - ipl) << sc->sc_pmr_shift) & 0xff;
        __asm volatile("msr "STR(ICC_PMR)", %x0" : : "r" (prival));
        __isb();
 
-       restore_interrupts(psw);
+       intr_restore(psw);
 }
 
 void
@@ -925,9 +925,9 @@ agintc_run_handler(struct intrhand *ih, void *frame, int s)
        else
                arg = frame;
 
-       enable_interrupts();
+       intr_enable();
        handled = ih->ih_func(arg);
-       disable_interrupts();
+       intr_disable();
        if (handled)
                ih->ih_count.ec_count++;
 
@@ -1027,7 +1027,7 @@ agintc_intr_establish(int irqno, int type, int level, struct cpu_info *ci,
 {
        struct agintc_softc     *sc = agintc_sc;
        struct intrhand         *ih;
-       int                      psw;
+       u_long                   psw;
 
        if (irqno < 0 || (irqno >= sc->sc_nintr && irqno < LPI_BASE) ||
            irqno >= LPI_BASE + sc->sc_nlpi)
@@ -1046,13 +1046,13 @@ agintc_intr_establish(int irqno, int type, int level, struct cpu_info *ci,
        ih->ih_name = name;
        ih->ih_ci = ci;
 
-       psw = disable_interrupts();
+       psw = intr_disable();
 
        if (irqno < LPI_BASE) {
                if (!TAILQ_EMPTY(&sc->sc_handler[irqno].iq_list) &&
                    sc->sc_handler[irqno].iq_ci != ci) {
+                       intr_restore(psw);
                        free(ih, M_DEVBUF, sizeof *ih);
-                       restore_interrupts(psw);
                        return NULL;
                }
                TAILQ_INSERT_TAIL(&sc->sc_handler[irqno].iq_list, ih, ih_list);
@@ -1081,7 +1081,7 @@ agintc_intr_establish(int irqno, int type, int level, struct cpu_info *ci,
                __asm volatile("dsb sy");
        }
 
-       restore_interrupts(psw);
+       intr_restore(psw);
        return (ih);
 }
 
@@ -1091,9 +1091,9 @@ agintc_intr_disestablish(void *cookie)
        struct agintc_softc     *sc = agintc_sc;
        struct intrhand         *ih = cookie;
        int                      irqno = ih->ih_irq;
-       int                      psw;
+       u_long                   psw;
 
-       psw = disable_interrupts();
+       psw = intr_disable();
 
        TAILQ_REMOVE(&sc->sc_handler[irqno].iq_list, ih, ih_list);
        if (ih->ih_name != NULL)
@@ -1101,7 +1101,7 @@ agintc_intr_disestablish(void *cookie)
 
        agintc_calc_irq(sc, irqno);
 
-       restore_interrupts(psw);
+       intr_restore(psw);
 
        free(ih, M_DEVBUF, 0);
 }
index 7e1b896..b44c226 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: ampintc.c,v 1.21 2021/02/17 12:11:45 kettenis Exp $ */
+/* $OpenBSD: ampintc.c,v 1.22 2021/05/15 11:30:27 kettenis Exp $ */
 /*
  * Copyright (c) 2007,2009,2011 Dale Rahn <drahn@openbsd.org>
  *
@@ -367,7 +367,7 @@ ampintc_attach(struct device *parent, struct device *self, void *aux)
        /* enable interrupts */
        bus_space_write_4(sc->sc_iot, sc->sc_d_ioh, ICD_DCR, 3);
        bus_space_write_4(sc->sc_iot, sc->sc_p_ioh, ICPICR, 1);
-       enable_interrupts();
+       intr_enable();
 
        sc->sc_ic.ic_node = faa->fa_node;
        sc->sc_ic.ic_cookie = self;
@@ -403,16 +403,16 @@ ampintc_setipl(int new)
 {
        struct cpu_info         *ci = curcpu();
        struct ampintc_softc    *sc = ampintc;
-       int                      psw;
+       u_long                   psw;
 
        /* disable here is only to keep hardware in sync with ci->ci_cpl */
-       psw = disable_interrupts();
+       psw = intr_disable();
        ci->ci_cpl = new;
 
        /* low values are higher priority thus IPL_HIGH - pri */
        bus_space_write_4(sc->sc_iot, sc->sc_p_ioh, ICPIPMR,
            (IPL_HIGH - new) << ICMIPMR_SH);
-       restore_interrupts(psw);
+       intr_restore(psw);
 }
 
 void
@@ -695,9 +695,9 @@ ampintc_irq_handler(void *frame)
                else
                        arg = frame;
 
-               enable_interrupts();
+               intr_enable();
                handled = ih->ih_func(arg);
-               disable_interrupts();
+               intr_disable();
                if (handled)
                        ih->ih_count.ec_count++;
 
@@ -745,7 +745,7 @@ ampintc_intr_establish(int irqno, int type, int level, struct cpu_info *ci,
 {
        struct ampintc_softc    *sc = ampintc;
        struct intrhand         *ih;
-       int                      psw;
+       u_long                   psw;
 
        if (irqno < 0 || irqno >= sc->sc_nintr)
                panic("ampintc_intr_establish: bogus irqnumber %d: %s",
@@ -771,12 +771,12 @@ ampintc_intr_establish(int irqno, int type, int level, struct cpu_info *ci,
        ih->ih_name = name;
        ih->ih_ci = ci;
 
-       psw = disable_interrupts();
+       psw = intr_disable();
 
        if (!TAILQ_EMPTY(&sc->sc_handler[irqno].iq_list) &&
            sc->sc_handler[irqno].iq_ci != ci) {
                free(ih, M_DEVBUF, sizeof(*ih));
-               restore_interrupts(psw);
+               intr_restore(psw);
                return NULL;
        }
 
@@ -794,7 +794,7 @@ ampintc_intr_establish(int irqno, int type, int level, struct cpu_info *ci,
        ampintc_intr_config(irqno, type);
        ampintc_calc_mask();
 
-       restore_interrupts(psw);
+       intr_restore(psw);
        return (ih);
 }
 
@@ -803,23 +803,24 @@ ampintc_intr_disestablish(void *cookie)
 {
        struct ampintc_softc    *sc = ampintc;
        struct intrhand         *ih = cookie;
-       int                      psw;
+       u_long                   psw;
 
 #ifdef DEBUG_INTC
        printf("ampintc_intr_disestablish irq %d level %d [%s]\n",
            ih->ih_irq, ih->ih_ipl, ih->ih_name);
 #endif
 
-       psw = disable_interrupts();
+       psw = intr_disable();
 
        TAILQ_REMOVE(&sc->sc_handler[ih->ih_irq].iq_list, ih, ih_list);
        if (ih->ih_name != NULL)
                evcount_detach(&ih->ih_count);
-       free(ih, M_DEVBUF, sizeof(*ih));
 
        ampintc_calc_mask();
 
-       restore_interrupts(psw);
+       intr_restore(psw);
+
+       free(ih, M_DEVBUF, sizeof(*ih));
 }
 
 const char *
index 40b36fd..9c6caf5 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: bcm2836_intr.c,v 1.10 2021/02/17 12:11:45 kettenis Exp $ */
+/* $OpenBSD: bcm2836_intr.c,v 1.11 2021/05/15 11:30:27 kettenis Exp $ */
 /*
  * Copyright (c) 2007,2009 Dale Rahn <drahn@openbsd.org>
  * Copyright (c) 2015 Patrick Wildt <patrick@blueri.se>
@@ -230,7 +230,7 @@ bcm_intc_attach(struct device *parent, struct device *self, void *aux)
        intr_send_ipi_func = bcm_intc_send_ipi;
        
        bcm_intc_setipl(IPL_HIGH);  /* XXX ??? */
-       enable_interrupts();
+       intr_enable();
 }
 
 void
@@ -357,9 +357,9 @@ bcm_intc_setipl(int new)
 {
        struct cpu_info *ci = curcpu();
        struct bcm_intc_softc *sc = bcm_intc;
-       int psw;
+       u_long psw;
 
-       psw = disable_interrupts();
+       psw = intr_disable();
        ci->ci_cpl = new;
        if (cpu_number() == 0) {
                bus_space_write_4(sc->sc_iot, sc->sc_ioh, INTC_DISABLE_BANK0,
@@ -380,7 +380,7 @@ bcm_intc_setipl(int new)
            ARM_LOCAL_INT_TIMER(cpu_number()),
            sc->sc_bcm_intc_imask[3][ci->ci_cpl] &
            sc->sc_localcoremask[cpu_number()]);
-       restore_interrupts(psw);
+       intr_restore(psw);
 }
 
 int
@@ -484,9 +484,9 @@ bcm_intc_call_handler(int irq, void *frame)
                else
                        arg = frame;
 
-               enable_interrupts();
+               intr_enable();
                handled = ih->ih_func(arg);
-               disable_interrupts();
+               intr_disable();
                if (handled)
                        ih->ih_count.ec_count++;
 
@@ -553,7 +553,7 @@ bcm_intc_intr_establish(int irqno, int level, struct cpu_info *ci,
 {
        struct bcm_intc_softc *sc = bcm_intc;
        struct intrhand *ih;
-       int psw;
+       u_long psw;
 
        if (irqno < 0 || irqno >= INTC_NIRQ)
                panic("bcm_intc_intr_establish: bogus irqnumber %d: %s",
@@ -562,7 +562,7 @@ bcm_intc_intr_establish(int irqno, int level, struct cpu_info *ci,
        if (ci != NULL && !CPU_IS_PRIMARY(ci))
                return NULL;
 
-       psw = disable_interrupts();
+       psw = intr_disable();
 
        ih = malloc(sizeof *ih, M_DEVBUF, M_WAITOK);
        ih->ih_func = func;
@@ -586,7 +586,7 @@ bcm_intc_intr_establish(int irqno, int level, struct cpu_info *ci,
 #endif
        bcm_intc_calc_mask();
 
-       restore_interrupts(psw);
+       intr_restore(psw);
        return (ih);
 }
 
@@ -596,14 +596,15 @@ bcm_intc_intr_disestablish(void *cookie)
        struct bcm_intc_softc *sc = bcm_intc;
        struct intrhand *ih = cookie;
        int irqno = ih->ih_irq;
-       int psw;
+       u_long psw;
 
-       psw = disable_interrupts();
+       psw = intr_disable();
        TAILQ_REMOVE(&sc->sc_bcm_intc_handler[irqno].is_list, ih, ih_list);
        if (ih->ih_name != NULL)
                evcount_detach(&ih->ih_count);
+       intr_restore(psw);
+
        free(ih, M_DEVBUF, 0);
-       restore_interrupts(psw);
 }
 
 void
index 4d885a6..e9809d9 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: efi.c,v 1.9 2021/03/11 11:16:56 jsg Exp $     */
+/*     $OpenBSD: efi.c,v 1.10 2021/05/15 11:30:27 kettenis Exp $       */
 
 /*
  * Copyright (c) 2017 Mark Kettenis <kettenis@openbsd.org>
@@ -49,7 +49,7 @@ struct efi_softc {
        struct device   sc_dev;
        struct pmap     *sc_pm;
        EFI_RUNTIME_SERVICES *sc_rs;
-       int             sc_psw;
+       u_long          sc_psw;
 
        struct todr_chip_handle sc_todr;
 };
@@ -227,7 +227,7 @@ efi_enter(struct efi_softc *sc)
 {
        struct pmap *pm = sc->sc_pm;
 
-       sc->sc_psw = disable_interrupts();
+       sc->sc_psw = intr_disable();
        WRITE_SPECIALREG(ttbr0_el1, pmap_kernel()->pm_pt0pa);
        __asm volatile("isb");
        cpu_setttb(pm->pm_asid, pm->pm_pt0pa);
@@ -245,7 +245,7 @@ efi_leave(struct efi_softc *sc)
        WRITE_SPECIALREG(ttbr0_el1, pmap_kernel()->pm_pt0pa);
        __asm volatile("isb");
        cpu_setttb(pm->pm_asid, pm->pm_pt0pa);
-       restore_interrupts(sc->sc_psw);
+       intr_restore(sc->sc_psw);
 }
 
 int
index f82d9fb..977a89e 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: cpu.h,v 1.19 2021/02/17 12:11:45 kettenis Exp $ */
+/* $OpenBSD: cpu.h,v 1.20 2021/05/15 11:30:27 kettenis Exp $ */
 /*
  * Copyright (c) 2016 Dale Rahn <drahn@dalerahn.com>
  *
@@ -255,15 +255,6 @@ void svc_handler   (trapframe_t *);
 void board_startup(void);
 
 // functions to manipulate interrupt state
-static __inline uint32_t
-get_daif(void)
-{
-       uint32_t daif;
-       
-       __asm volatile ("mrs %x0, daif": "=r"(daif));
-       return daif;
-}
-
 static __inline void
 restore_daif(uint32_t daif)
 {
@@ -291,18 +282,6 @@ disable_irq_daif_ret(void)
        return daif;
 }
 
-#define get_interrupts(mask)                                           \
-       (__get_daif())
-
-#define disable_interrupts()                                           \
-       disable_irq_daif_ret()
-
-#define enable_interrupts()                                            \
-       enable_irq_daif()
-
-#define restore_interrupts(old_daif)                                   \
-       restore_daif(old_daif)
-
 static inline void
 intr_enable(void)
 {