Source-Changes-HG archive

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

[src/trunk]: src/sys/arch sti/cli are not allowed on Xen, we have to clear/se...



details:   https://anonhg.NetBSD.org/src/rev/190ce7834e5c
branches:  trunk
changeset: 451202:190ce7834e5c
user:      bouyer <bouyer%NetBSD.org@localhost>
date:      Thu May 09 17:09:50 2019 +0000

description:
sti/cli are not allowed on Xen, we have to clear/set a bit in the
shared page. Revert x86_disable_intr/x86_enable_intr to plain function
calls on XENPV.
While there, clean up unused functions and macros, and change cli()/sti()
macros to x86_disable_intr/x86_enable_intr.
Makes Xen domU boot again
(http://www-soc.lip6.fr/~bouyer/NetBSD-tests/xen/HEAD/)

diffstat:

 sys/arch/x86/include/cpufunc.h        |  10 ++++++-
 sys/arch/xen/include/xen.h            |  51 +----------------------------------
 sys/arch/xen/include/xenfunc.h        |   4 +--
 sys/arch/xen/x86/hypervisor_machdep.c |   8 ++--
 sys/arch/xen/x86/xen_intr.c           |  23 +++++++++------
 sys/arch/xen/xen/evtchn.c             |  14 ++++----
 6 files changed, 36 insertions(+), 74 deletions(-)

diffs (279 lines):

diff -r d06e549f18b6 -r 190ce7834e5c sys/arch/x86/include/cpufunc.h
--- a/sys/arch/x86/include/cpufunc.h    Thu May 09 16:48:31 2019 +0000
+++ b/sys/arch/x86/include/cpufunc.h    Thu May 09 17:09:50 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cpufunc.h,v 1.27 2019/05/04 07:20:22 maxv Exp $        */
+/*     $NetBSD: cpufunc.h,v 1.28 2019/05/09 17:09:50 bouyer Exp $      */
 
 /*
  * Copyright (c) 1998, 2007, 2019 The NetBSD Foundation, Inc.
@@ -43,6 +43,9 @@
 #include <machine/specialreg.h>
 
 #ifdef _KERNEL
+#if defined(_KERNEL_OPT)
+#include "opt_xen.h"
+#endif
 
 static inline void
 x86_pause(void)
@@ -291,6 +294,10 @@
 
 /* -------------------------------------------------------------------------- */
 
+#ifdef XENPV
+void x86_disable_intr(void);
+void x86_enable_intr(void);
+#else
 static inline void
 x86_disable_intr(void)
 {
@@ -302,6 +309,7 @@
 {
        asm volatile ("sti");
 }
+#endif /* XENPV */
 
 /* Use read_psl, write_psl when saving and restoring interrupt state. */
 u_long x86_read_psl(void);
diff -r d06e549f18b6 -r 190ce7834e5c sys/arch/xen/include/xen.h
--- a/sys/arch/xen/include/xen.h        Thu May 09 16:48:31 2019 +0000
+++ b/sys/arch/xen/include/xen.h        Thu May 09 17:09:50 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: xen.h,v 1.43 2019/02/04 18:14:53 cherry Exp $  */
+/*     $NetBSD: xen.h,v 1.44 2019/05/09 17:09:50 bouyer Exp $  */
 
 /*
  *
@@ -136,55 +136,6 @@
 #define xendomain_is_privileged()      (xen_start_info.flags & SIF_PRIVILEGED)
 
 /*
- * STI/CLI equivalents. These basically set and clear the virtual
- * event_enable flag in the shared_info structure. Note that when
- * the enable bit is set, there may be pending events to be handled.
- * We may therefore call into do_hypervisor_callback() directly.
- */
-
-#define __save_flags(x)                                                        \
-do {                                                                   \
-       (x) = curcpu()->ci_vcpu->evtchn_upcall_mask;                    \
-} while (0)
-
-#define __restore_flags(x)                                             \
-do {                                                                   \
-       volatile struct vcpu_info *_vci = curcpu()->ci_vcpu;            \
-       __insn_barrier();                                               \
-       if ((_vci->evtchn_upcall_mask = (x)) == 0) {                    \
-               x86_lfence();                                           \
-               if (__predict_false(_vci->evtchn_upcall_pending))       \
-                       hypervisor_force_callback();                    \
-       }                                                               \
-} while (0)
-
-#define __cli()                                                                \
-do {                                                                   \
-       curcpu()->ci_vcpu->evtchn_upcall_mask = 1;                      \
-       x86_lfence();                                                   \
-} while (0)
-
-#define __sti()                                                                \
-do {                                                                   \
-       volatile struct vcpu_info *_vci = curcpu()->ci_vcpu;            \
-       __insn_barrier();                                               \
-       _vci->evtchn_upcall_mask = 0;                                   \
-       x86_lfence(); /* unmask then check (avoid races) */             \
-       if (__predict_false(_vci->evtchn_upcall_pending))               \
-               hypervisor_force_callback();                            \
-} while (0)
-
-#define cli()                  __cli()
-#define sti()                  __sti()
-#define save_flags(x)          __save_flags(x)
-#define restore_flags(x)       __restore_flags(x)
-#define save_and_cli(x)        do {                                    \
-       __save_flags(x);                                        \
-       __cli();                                                \
-} while (/* CONSTCOND */ 0)
-#define save_and_sti(x)                __save_and_sti(x)
-
-/*
  * always assume we're on multiprocessor. We don't know how many CPU the
  * underlying hardware has.
  */
diff -r d06e549f18b6 -r 190ce7834e5c sys/arch/xen/include/xenfunc.h
--- a/sys/arch/xen/include/xenfunc.h    Thu May 09 16:48:31 2019 +0000
+++ b/sys/arch/xen/include/xenfunc.h    Thu May 09 17:09:50 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: xenfunc.h,v 1.17 2019/02/12 08:04:53 cherry Exp $      */
+/*     $NetBSD: xenfunc.h,v 1.18 2019/05/09 17:09:50 bouyer Exp $      */
 
 /*
  *
@@ -36,8 +36,6 @@
 #include <xen/xenpmap.h>
 #include <machine/pte.h>
 
-void xen_disable_intr(void);
-void xen_enable_intr(void);
 u_long xen_read_psl(void);
 void xen_write_psl(u_long);
 
diff -r d06e549f18b6 -r 190ce7834e5c sys/arch/xen/x86/hypervisor_machdep.c
--- a/sys/arch/xen/x86/hypervisor_machdep.c     Thu May 09 16:48:31 2019 +0000
+++ b/sys/arch/xen/x86/hypervisor_machdep.c     Thu May 09 17:09:50 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: hypervisor_machdep.c,v 1.35 2019/02/12 07:58:26 cherry Exp $   */
+/*     $NetBSD: hypervisor_machdep.c,v 1.36 2019/05/09 17:09:51 bouyer Exp $   */
 
 /*
  *
@@ -54,7 +54,7 @@
 
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: hypervisor_machdep.c,v 1.35 2019/02/12 07:58:26 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hypervisor_machdep.c,v 1.36 2019/05/09 17:09:51 bouyer Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -192,7 +192,7 @@
         */
 
        while (vci->evtchn_upcall_pending) {
-               cli();
+               x86_disable_intr();
 
                vci->evtchn_upcall_pending = 0;
 
@@ -200,7 +200,7 @@
                    s->evtchn_pending, s->evtchn_mask,
                    evt_set_pending, &ret);
 
-               sti();
+               x86_enable_intr();
        }
 
 #if 0
diff -r d06e549f18b6 -r 190ce7834e5c sys/arch/xen/x86/xen_intr.c
--- a/sys/arch/xen/x86/xen_intr.c       Thu May 09 16:48:31 2019 +0000
+++ b/sys/arch/xen/x86/xen_intr.c       Thu May 09 17:09:50 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: xen_intr.c,v 1.15 2019/02/14 08:18:26 cherry Exp $     */
+/*     $NetBSD: xen_intr.c,v 1.16 2019/05/09 17:09:51 bouyer Exp $     */
 
 /*-
  * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: xen_intr.c,v 1.15 2019/02/14 08:18:26 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xen_intr.c,v 1.16 2019/05/09 17:09:51 bouyer Exp $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
@@ -87,7 +87,7 @@
 
        xmask = XUNMASK(ci, nlevel);
        psl = xen_read_psl();
-       xen_disable_intr();
+       x86_disable_intr();
        if (ci->ci_xpending & xmask) {
                KASSERT(psl == 0);
                Xspllower(nlevel);
@@ -98,16 +98,23 @@
        }
 }
 
+
 void
-xen_disable_intr(void)
+x86_disable_intr(void)
 {
-       __cli();
+       curcpu()->ci_vcpu->evtchn_upcall_mask = 1;
+       x86_lfence();
 }
 
 void
-xen_enable_intr(void)
+x86_enable_intr(void)
 {
-       __sti();
+       volatile struct vcpu_info *_vci = curcpu()->ci_vcpu;
+       __insn_barrier();
+       _vci->evtchn_upcall_mask = 0;
+       x86_lfence(); /* unmask then check (avoid races) */
+       if (__predict_false(_vci->evtchn_upcall_pending))
+               hypervisor_force_callback();
 }
 
 u_long
@@ -493,8 +500,6 @@
 
 #if !defined(XENPVHVM)
 __strong_alias(spllower, xen_spllower);
-__strong_alias(x86_disable_intr, xen_disable_intr);
-__strong_alias(x86_enable_intr, xen_enable_intr);
 __strong_alias(x86_read_psl, xen_read_psl);
 __strong_alias(x86_write_psl, xen_write_psl);
 
diff -r d06e549f18b6 -r 190ce7834e5c sys/arch/xen/xen/evtchn.c
--- a/sys/arch/xen/xen/evtchn.c Thu May 09 16:48:31 2019 +0000
+++ b/sys/arch/xen/xen/evtchn.c Thu May 09 17:09:50 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: evtchn.c,v 1.85 2019/02/13 06:52:43 cherry Exp $       */
+/*     $NetBSD: evtchn.c,v 1.86 2019/05/09 17:09:51 bouyer Exp $       */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -54,7 +54,7 @@
 
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: evtchn.c,v 1.85 2019/02/13 06:52:43 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: evtchn.c,v 1.86 2019/05/09 17:09:51 bouyer Exp $");
 
 #include "opt_xen.h"
 #include "isa.h"
@@ -368,7 +368,7 @@
        }
        ci->ci_ilevel = evtsource[evtch]->ev_maxlevel;
        iplmask = evtsource[evtch]->ev_imask;
-       sti();
+       x86_enable_intr();
        mutex_spin_enter(&evtlock[evtch]);
        ih = evtsource[evtch]->ev_handlers;
        while (ih != NULL) {
@@ -383,7 +383,7 @@
                if (evtch == IRQ_DEBUG)
                    printf("ih->ih_level %d <= ilevel %d\n", ih->ih_level, ilevel);
 #endif
-                       cli();
+                       x86_disable_intr();
                        hypervisor_set_ipending(iplmask,
                            evtch >> LONG_SHIFT, evtch & LONG_MASK);
                        /* leave masked */
@@ -397,7 +397,7 @@
                ih = ih->ih_evt_next;
        }
        mutex_spin_exit(&evtlock[evtch]);
-       cli();
+       x86_disable_intr();
        hypervisor_unmask_event(evtch);
 #if NPCI > 0 || NISA > 0
        hypervisor_ack_pirq_event(evtch);
@@ -419,10 +419,10 @@
                                for (ih = ci->ci_xsources[i]->is_handlers;
                                    ih != NULL; ih = ih->ih_next) {
                                        KASSERT(ih->ih_cpu == ci);
-                                       sti();
+                                       x86_enable_intr();
                                        ih_fun = (void *)ih->ih_fun;
                                        ih_fun(ih->ih_arg, regs);
-                                       cli();
+                                       x86_disable_intr();
                                }
                                hypervisor_enable_ipl(i);
                                /* more pending IPLs may have been registered */



Home | Main Index | Thread Index | Old Index