Source-Changes-HG archive

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

[src/bouyer-xenpvh]: src/sys/arch Move softint and preemtion-related function...



details:   https://anonhg.NetBSD.org/src/rev/9f2a8937abcc
branches:  bouyer-xenpvh
changeset: 982919:9f2a8937abcc
user:      bouyer <bouyer%NetBSD.org@localhost>
date:      Sat Apr 11 18:26:06 2020 +0000

description:
Move softint and preemtion-related functions out of x86/x86/intr.c to
  its own file, x86/x86/x86_softintr.c
Add x86/x86/x86_softintr.c for native and XenPV
Make sure XenPV also check ci_ioending, which is used for softints.
Switch XenPV to fast softints and allow kernel preemption.
kpreempt_disable() before calling pmap_changeprot_local()
run  xen_wallclock_time() and xen_global_systime_ns() at splshed() to
  avoid being interrupted.

XXX amd64 lock stubs are racy for XPENDING

diffstat:

 sys/arch/amd64/amd64/lock_stubs.S |    7 +-
 sys/arch/amd64/amd64/spl.S        |   24 +-
 sys/arch/i386/i386/spl.S          |   24 +-
 sys/arch/x86/conf/files.x86       |    3 +-
 sys/arch/x86/include/intr.h       |    7 +-
 sys/arch/x86/x86/intr.c           |  161 +-------------------
 sys/arch/x86/x86/x86_machdep.c    |    8 +-
 sys/arch/x86/x86/x86_softintr.c   |  289 ++++++++++++++++++++++++++++++++++++++
 sys/arch/xen/conf/files.xen       |    3 +-
 sys/arch/xen/include/intrdefs.h   |    7 +-
 sys/arch/xen/x86/xen_ipi.c        |   16 +-
 sys/arch/xen/x86/xenfunc.c        |   12 +-
 sys/arch/xen/xen/clock.c          |   11 +-
 13 files changed, 367 insertions(+), 205 deletions(-)

diffs (truncated from 1098 to 300 lines):

diff -r 3d688093f2ba -r 9f2a8937abcc sys/arch/amd64/amd64/lock_stubs.S
--- a/sys/arch/amd64/amd64/lock_stubs.S Sat Apr 11 12:01:42 2020 +0000
+++ b/sys/arch/amd64/amd64/lock_stubs.S Sat Apr 11 18:26:06 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lock_stubs.S,v 1.35 2019/12/08 20:00:56 ad Exp $       */
+/*     $NetBSD: lock_stubs.S,v 1.35.6.1 2020/04/11 18:26:06 bouyer Exp $       */
 
 /*
  * Copyright (c) 2006, 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -126,15 +126,12 @@
        jnz     1f
        cmpl    CPU_INFO_ILEVEL(%r8), %edi
        jae     1f
-#if !defined(XENPV)
        movl    CPU_INFO_IUNMASK(%r8,%rdi,4), %esi
        CLI(ax)
        testl   CPU_INFO_IPENDING(%r8), %esi
        jnz     _C_LABEL(Xspllower)
-#endif
 #if defined(XEN)
        movl    CPU_INFO_XUNMASK(%r8,%rdi,4), %esi
-       CLI(ax)
        testl   CPU_INFO_XPENDING(%r8), %esi
        jnz     _C_LABEL(Xspllower)
 #endif
@@ -155,14 +152,12 @@
        cmpl    %edx,%ecx                       /* new level is lower? */
        jae     2f
 1:
-#if !defined(XENPV)
        movl    CPU_INFO_IPENDING(%rsi),%eax
        testl   %eax,CPU_INFO_IUNMASK(%rsi,%rcx,4)/* deferred interrupts? */
        jnz     3f
        movl    %eax,%ebx
        cmpxchg8b CPU_INFO_ISTATE(%rsi)         /* swap in new ilevel */
        jnz     4f
-#endif
 #if defined(XEN)
        movl    CPU_INFO_XPENDING(%rsi),%eax
        testl   %eax,CPU_INFO_XUNMASK(%rsi,%rcx,4)/* deferred interrupts? */
diff -r 3d688093f2ba -r 9f2a8937abcc sys/arch/amd64/amd64/spl.S
--- a/sys/arch/amd64/amd64/spl.S        Sat Apr 11 12:01:42 2020 +0000
+++ b/sys/arch/amd64/amd64/spl.S        Sat Apr 11 18:26:06 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: spl.S,v 1.43.4.4 2020/04/11 10:11:30 bouyer Exp $      */
+/*     $NetBSD: spl.S,v 1.43.4.5 2020/04/11 18:26:06 bouyer Exp $      */
 
 /*
  * Copyright (c) 2003 Wasabi Systems, Inc.
@@ -91,7 +91,6 @@
        ret
 END(splraise)
 
-#ifndef XENPV
 /*
  * Xsoftintr()
  *
@@ -148,11 +147,11 @@
        movq    PCB_RSP0(%rdx),%rsp
 
        /* dispatch */
-       sti
+       STI(di)
        movq    %r15,%rdi               /* interrupted LWP */
        movl    IS_MAXLEVEL(%rax),%esi  /* ipl to run at */
        call    _C_LABEL(softint_dispatch)/* run handlers */
-       cli
+       CLI(di)
 
        /* restore old context */
        movq    L_PCB(%r15),%rcx
@@ -174,7 +173,7 @@
  */
 ENTRY(softintr_ret)
        incl    CPUVAR(MTX_COUNT)       /* re-adjust after mi_switch */
-       cli
+       CLI(ax)         /* %rax not used by Xspllower/Xdoreti */
        jmp     *%r13                   /* back to Xspllower/Xdoreti */
 END(softintr_ret)
 
@@ -196,11 +195,11 @@
  */
 IDTVEC(recurse_preempt)
        movl    $IPL_PREEMPT,CPUVAR(ILEVEL)
-       sti
+       STI(di)
        xorq    %rdi,%rdi
        KMSAN_INIT_ARG(8)
        call    _C_LABEL(kpreempt)
-       cli
+       CLI(di)
        jmp     *%r13                   /* back to Xspllower */
 IDTVEC_END(recurse_preempt)
 
@@ -211,20 +210,19 @@
  */
 IDTVEC(resume_preempt)
        movl    $IPL_PREEMPT,CPUVAR(ILEVEL)
-       sti
+       STI(ax)
        testq   $SEL_RPL,TF_CS(%rsp)
        jnz     1f
        movq    TF_RIP(%rsp),%rdi
        KMSAN_INIT_ARG(8)
        call    _C_LABEL(kpreempt)      /* from kernel */
-       cli
+       CLI(ax)
        jmp     *%r13                   /* back to Xdoreti */
 1:
        call    _C_LABEL(preempt)       /* from user */
-       cli
+       CLI(ax)
        jmp     *%r13                   /* back to Xdoreti */
 IDTVEC_END(resume_preempt)
-#endif /* XEN */
 
 /*
  * void spllower(int s);
@@ -336,7 +334,6 @@
        movl    %edi,%ebx
        leaq    1f(%rip),%r13           /* address to resume loop at */
 1:
-#if !defined(XENPV)
        movl    %ebx,%eax               /* get cpl */
        movl    CPUVAR(IUNMASK)(,%rax,4),%eax
        CLI(si)
@@ -346,7 +343,6 @@
        btrl    %eax,CPUVAR(IPENDING)
        movq    CPUVAR(ISOURCES)(,%rax,8),%rax
        jmp     *IS_RECURSE(%rax)
-#endif
 2:
 #if defined(XEN)
        movl    %ebx,%eax               /* get cpl */
@@ -382,7 +378,6 @@
        decl    CPUVAR(IDEPTH)
        leaq    1f(%rip),%r13
 1:
-#if !defined(XENPV)
        movl    %ebx,%eax
        movl    CPUVAR(IUNMASK)(,%rax,4),%eax
        CLI(si)
@@ -392,7 +387,6 @@
        btrl    %eax,CPUVAR(IPENDING)
        movq    CPUVAR(ISOURCES)(,%rax,8),%rax
        jmp     *IS_RESUME(%rax)
-#endif
 2:
 #if defined(XEN)
        movl    %ebx,%eax
diff -r 3d688093f2ba -r 9f2a8937abcc sys/arch/i386/i386/spl.S
--- a/sys/arch/i386/i386/spl.S  Sat Apr 11 12:01:42 2020 +0000
+++ b/sys/arch/i386/i386/spl.S  Sat Apr 11 18:26:06 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: spl.S,v 1.50.4.3 2020/04/11 12:01:42 bouyer Exp $      */
+/*     $NetBSD: spl.S,v 1.50.4.4 2020/04/11 18:26:07 bouyer Exp $      */
 
 /*
  * Copyright (c) 1998, 2007, 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <machine/asm.h>
-__KERNEL_RCSID(0, "$NetBSD: spl.S,v 1.50.4.3 2020/04/11 12:01:42 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: spl.S,v 1.50.4.4 2020/04/11 18:26:07 bouyer Exp $");
 
 #include "opt_ddb.h"
 #include "opt_spldebug.h"
@@ -213,7 +213,6 @@
        jz      .Lspllower_panic
 #endif /* XENPV */
 #endif /* defined(DEBUG) */
-#if !defined(XENPV)
        movl    %ebx,%eax                       /* get cpl */
        movl    CPUVAR(IUNMASK)(,%eax,4),%eax
        andl    CPUVAR(IPENDING),%eax           /* any non-masked bits left? */
@@ -222,7 +221,6 @@
        btrl    %eax,CPUVAR(IPENDING)
        movl    CPUVAR(ISOURCES)(,%eax,4),%eax
        jmp     *IS_RECURSE(%eax)
-#endif
 2:
 #if defined(XEN)
        movl    %ebx,%eax                       /* get cpl */
@@ -361,7 +359,6 @@
 #endif
 IDTVEC_END(doreti)
 
-#ifndef XENPV
 /*
  * Xsoftintr()
  *
@@ -379,6 +376,7 @@
        pushl   %esi
        pushl   %edi
        movl    $IPL_HIGH,CPUVAR(ILEVEL)
+       STI(%esi)
        movl    CPUVAR(CURLWP),%esi
        movl    IS_LWP(%eax),%edi       /* switch to handler LWP */
        movl    %edi,CPUVAR(CURLWP)
@@ -387,12 +385,11 @@
        movl    %esp,PCB_ESP(%ecx)
        movl    %ebp,PCB_EBP(%ecx)
        movl    PCB_ESP0(%edx),%esp     /* onto new stack */
-       sti
        pushl   IS_MAXLEVEL(%eax)       /* ipl to run at */
        pushl   %esi
        call    _C_LABEL(softint_dispatch)/* run handlers */
        addl    $8,%esp
-       cli
+       CLI(%ecx)
        movl    L_PCB(%esi),%ecx
        movl    PCB_ESP(%ecx),%esp
        xchgl   %esi,CPUVAR(CURLWP)     /* must be globally visible */
@@ -412,7 +409,7 @@
  */
 ENTRY(softintr_ret)
        incl    CPUVAR(MTX_COUNT)       /* re-adjust after mi_switch */
-       cli
+       CLI(%eax)
        jmp     *%esi                   /* back to splx/doreti */
 END(softintr_ret)
 
@@ -434,11 +431,11 @@
  */
 IDTVEC(recurse_preempt)
        movl    $IPL_PREEMPT,CPUVAR(ILEVEL)
-       sti
+       STI(%eax)
        pushl   $0
        call    _C_LABEL(kpreempt)
        addl    $4,%esp
-       cli
+       CLI(%eax)
        jmp     *%esi
 IDTVEC_END(recurse_preempt)
 
@@ -449,18 +446,17 @@
  */
 IDTVEC(resume_preempt)
        movl    $IPL_PREEMPT,CPUVAR(ILEVEL)
-       sti
+       STI(%eax)
        testb   $CHK_UPL,TF_CS(%esp)
        jnz     1f
        movl    TF_EIP(%esp),%eax
        pushl   %eax
        call    _C_LABEL(kpreempt)              /* from kernel */
        addl    $4,%esp
-       cli
+       CLI(%eax)
        jmp     *%esi
 1:
        call    _C_LABEL(preempt)               /* from user */
-       cli
+       CLI(%eax)
        jmp     *%esi
 IDTVEC_END(resume_preempt)
-#endif /* !XENPV */
diff -r 3d688093f2ba -r 9f2a8937abcc sys/arch/x86/conf/files.x86
--- a/sys/arch/x86/conf/files.x86       Sat Apr 11 12:01:42 2020 +0000
+++ b/sys/arch/x86/conf/files.x86       Sat Apr 11 18:26:06 2020 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.x86,v 1.107 2019/02/15 08:54:01 nonaka Exp $
+#      $NetBSD: files.x86,v 1.107.10.1 2020/04/11 18:26:07 bouyer Exp $
 
 # options for MP configuration through the MP spec
 defflag opt_mpbios.h MPBIOS MPDEBUG MPBIOS_SCANPCI
@@ -93,6 +93,7 @@
 file   arch/x86/x86/identcpu.c         machdep
 file   arch/x86/x86/i8259.c            machdep
 file   arch/x86/x86/intr.c             machdep
+file   arch/x86/x86/x86_softintr.c     machdep
 file   arch/x86/x86/kgdb_machdep.c     kgdb
 file   arch/x86/x86/nmi.c              machdep
 file   arch/x86/x86/idt.c              machdep
diff -r 3d688093f2ba -r 9f2a8937abcc sys/arch/x86/include/intr.h
--- a/sys/arch/x86/include/intr.h       Sat Apr 11 12:01:42 2020 +0000
+++ b/sys/arch/x86/include/intr.h       Sat Apr 11 18:26:06 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: intr.h,v 1.61.6.1 2020/04/10 14:42:00 bouyer Exp $     */
+/*     $NetBSD: intr.h,v 1.61.6.2 2020/04/11 18:26:07 bouyer Exp $     */
 
 /*-
  * Copyright (c) 1998, 2001, 2006, 2007, 2008, 2019 The NetBSD Foundation, Inc.
@@ -32,12 +32,10 @@
 #ifndef _X86_INTR_H_
 #define _X86_INTR_H_
 
-#if !defined(XENPV)
 #define        __HAVE_FAST_SOFTINTS
 #if !defined(NO_PREEMPTION)
 #define        __HAVE_PREEMPTION
 #endif /* !defined(NO_PREEMPTION) */
-#endif /*  !defined(XENPV) */
 
 #ifdef _KERNEL
 #include <sys/types.h>
@@ -239,6 +237,9 @@
 struct intrsource *intr_allocate_io_intrsource(const char *);



Home | Main Index | Thread Index | Old Index