Module Name: src Committed By: bouyer Date: Wed Apr 15 16:04:07 UTC 2020
Modified Files: src/sys/arch/amd64/amd64 [bouyer-xenpvh]: spl.S src/sys/arch/amd64/conf [bouyer-xenpvh]: XEN3_DOMU src/sys/arch/i386/i386 [bouyer-xenpvh]: lock_stubs.S spl.S src/sys/arch/x86/include [bouyer-xenpvh]: cpufunc.h src/sys/arch/x86/x86 [bouyer-xenpvh]: patch.c Log Message: On amd64, always use the cmpxchg8b version of spllower. All x86_64 host should have it and we already rely on it in lock stubs. On i386, always use i686_mutex_spin_exit and cx8_spllower for Xen; Xen doesn't run on CPUs on CPUs lacking the required instructions anyway. Skip x86_patch only for XENPV, and adjust for changes in assembly functions. Tested on Xen PV and PVHVM, and on bare metal core i5. To generate a diff of this commit: cvs rdiff -u -r1.43.4.6 -r1.43.4.7 src/sys/arch/amd64/amd64/spl.S cvs rdiff -u -r1.90.6.1 -r1.90.6.2 src/sys/arch/amd64/conf/XEN3_DOMU cvs rdiff -u -r1.32 -r1.32.6.1 src/sys/arch/i386/i386/lock_stubs.S cvs rdiff -u -r1.50.4.5 -r1.50.4.6 src/sys/arch/i386/i386/spl.S cvs rdiff -u -r1.37 -r1.37.6.1 src/sys/arch/x86/include/cpufunc.h cvs rdiff -u -r1.37.6.2 -r1.37.6.3 src/sys/arch/x86/x86/patch.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/arch/amd64/amd64/spl.S diff -u src/sys/arch/amd64/amd64/spl.S:1.43.4.6 src/sys/arch/amd64/amd64/spl.S:1.43.4.7 --- src/sys/arch/amd64/amd64/spl.S:1.43.4.6 Sun Apr 12 17:25:52 2020 +++ src/sys/arch/amd64/amd64/spl.S Wed Apr 15 16:04:06 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: spl.S,v 1.43.4.6 2020/04/12 17:25:52 bouyer Exp $ */ +/* $NetBSD: spl.S,v 1.43.4.7 2020/04/15 16:04:06 bouyer Exp $ */ /* * Copyright (c) 2003 Wasabi Systems, Inc. @@ -227,50 +227,12 @@ IDTVEC_END(resume_preempt) /* * void spllower(int s); * - * Must be the same size as cx8_spllower(). This must use - * pushf/cli/popf as it is used early in boot where interrupts - * are disabled via eflags/IE. - */ -ENTRY(spllower) - cmpl CPUVAR(ILEVEL),%edi - jae 1f - movl CPUVAR(IUNMASK)(,%rdi,4),%edx - PUSHF(ax) - CLI(ax) - testl CPUVAR(IPENDING),%edx - jnz 2f - movl %edi,CPUVAR(ILEVEL) - POPF /* clobbers %rdi */ -1: - ret - ret -2: -#ifdef XENPV - /* - * no need to call stipending, we're going to CLI again - * just drop the saved value on stack - */ - addq $8,%rsp -#else - popf -#endif - jmp _C_LABEL(Xspllower) -3: - .space 16 - .align 16 -END(spllower) -LABEL(spllower_end) - -#ifndef XENPV -/* - * void cx8_spllower(int s); - * * For cmpxchg8b, edx/ecx are the high words and eax/ebx the low. * * edx : eax = old level / old ipending * ecx : ebx = new level / old ipending */ -ENTRY(cx8_spllower) +ENTRY(spllower) movl CPUVAR(ILEVEL),%edx movq %rbx,%r8 cmpl %edx,%edi /* new level is lower? */ @@ -292,15 +254,11 @@ ENTRY(cx8_spllower) ret 2: movq %r8,%rbx - .type _C_LABEL(cx8_spllower_patch), @function -LABEL(cx8_spllower_patch) jmp _C_LABEL(Xspllower) .align 16 -END(cx8_spllower_patch) -END(cx8_spllower) -LABEL(cx8_spllower_end) -#endif /* !XENPV */ +END(spllower) +LABEL(spllower_end) /* * void Xspllower(int s); Index: src/sys/arch/amd64/conf/XEN3_DOMU diff -u src/sys/arch/amd64/conf/XEN3_DOMU:1.90.6.1 src/sys/arch/amd64/conf/XEN3_DOMU:1.90.6.2 --- src/sys/arch/amd64/conf/XEN3_DOMU:1.90.6.1 Wed Apr 8 17:56:08 2020 +++ src/sys/arch/amd64/conf/XEN3_DOMU Wed Apr 15 16:04:06 2020 @@ -1,17 +1,19 @@ -# $NetBSD: XEN3_DOMU,v 1.90.6.1 2020/04/08 17:56:08 bouyer Exp $ +# $NetBSD: XEN3_DOMU,v 1.90.6.2 2020/04/15 16:04:06 bouyer Exp $ include "arch/amd64/conf/std.xen" options XENPV # PV domU support options MULTIPROCESSOR +options HZ=20 + options INCLUDE_CONFIG_FILE # embed config file in kernel binary #options UVMHIST #options UVMHIST_PRINT #options SYSCALL_DEBUG -#ident "XEN3_DOMU-$Revision: 1.90.6.1 $" +#ident "XEN3_DOMU-$Revision: 1.90.6.2 $" maxusers 32 # estimated number of users Index: src/sys/arch/i386/i386/lock_stubs.S diff -u src/sys/arch/i386/i386/lock_stubs.S:1.32 src/sys/arch/i386/i386/lock_stubs.S:1.32.6.1 --- src/sys/arch/i386/i386/lock_stubs.S:1.32 Sun Dec 8 20:00:56 2019 +++ src/sys/arch/i386/i386/lock_stubs.S Wed Apr 15 16:04:06 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: lock_stubs.S,v 1.32 2019/12/08 20:00:56 ad Exp $ */ +/* $NetBSD: lock_stubs.S,v 1.32.6.1 2020/04/15 16:04:06 bouyer Exp $ */ /*- * Copyright (c) 2006, 2007, 2008, 2009 The NetBSD Foundation, Inc. @@ -35,7 +35,7 @@ */ #include <machine/asm.h> -__KERNEL_RCSID(0, "$NetBSD: lock_stubs.S,v 1.32 2019/12/08 20:00:56 ad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: lock_stubs.S,v 1.32.6.1 2020/04/15 16:04:06 bouyer Exp $"); #include "opt_lockdebug.h" @@ -223,7 +223,6 @@ ENTRY(rw_tryenter) jmp 3b END(rw_tryenter) -#ifndef XENPV /* * void mutex_spin_enter(kmutex_t *mtx); @@ -254,6 +253,7 @@ ENTRY(mutex_spin_enter) LABEL(mutex_spin_enter_end) END(mutex_spin_enter) +#ifndef XENPV /* * Release a spin mutex and post a store fence. */ @@ -275,7 +275,9 @@ ENTRY(mutex_spin_exit) .align 32 LABEL(mutex_spin_exit_end) END(mutex_spin_exit) - +#else /* XENPV */ +STRONG_ALIAS(mutex_spin_exit, i686_mutex_spin_exit) +#endif /* !XENPV */ /* * Patch for i686 CPUs where cli/sti is prohibitively expensive. * Must be the same size as mutex_spin_exit(). @@ -307,17 +309,6 @@ LABEL(i686_mutex_spin_exit_patch) LABEL(i686_mutex_spin_exit_end) END(i686_mutex_spin_exit) -#else /* !XENPV */ - -/* For now; strong alias not working for some reason. */ -ENTRY(mutex_spin_enter) - jmp _C_LABEL(mutex_vector_enter) - -ENTRY(mutex_spin_exit) - jmp _C_LABEL(mutex_vector_exit) - -#endif /* !XENPV */ - #endif /* !LOCKDEBUG */ /* Index: src/sys/arch/i386/i386/spl.S diff -u src/sys/arch/i386/i386/spl.S:1.50.4.5 src/sys/arch/i386/i386/spl.S:1.50.4.6 --- src/sys/arch/i386/i386/spl.S:1.50.4.5 Sun Apr 12 17:25:52 2020 +++ src/sys/arch/i386/i386/spl.S Wed Apr 15 16:04:06 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: spl.S,v 1.50.4.5 2020/04/12 17:25:52 bouyer Exp $ */ +/* $NetBSD: spl.S,v 1.50.4.6 2020/04/15 16:04:06 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.5 2020/04/12 17:25:52 bouyer Exp $"); +__KERNEL_RCSID(0, "$NetBSD: spl.S,v 1.50.4.6 2020/04/15 16:04:06 bouyer Exp $"); #include "opt_ddb.h" #include "opt_spldebug.h" @@ -67,6 +67,7 @@ ENTRY(splraise) ret END(splraise) +#ifndef XENPV /* * void spllower(int s); * @@ -110,8 +111,10 @@ ENTRY(spllower) .align 32 LABEL(spllower_end) END(spllower) +#else /* XENPV */ +STRONG_ALIAS(spllower, cx8_spllower) +#endif /* !XENPV */ -#ifndef XENPV /* * void cx8_spllower(int s); * @@ -151,8 +154,6 @@ LABEL(cx8_spllower_patch) LABEL(cx8_spllower_end) END(cx8_spllower) -#endif /* XENPV */ - /* * void Xspllower(int s); * Index: src/sys/arch/x86/include/cpufunc.h diff -u src/sys/arch/x86/include/cpufunc.h:1.37 src/sys/arch/x86/include/cpufunc.h:1.37.6.1 --- src/sys/arch/x86/include/cpufunc.h:1.37 Wed Oct 30 17:06:57 2019 +++ src/sys/arch/x86/include/cpufunc.h Wed Apr 15 16:04:06 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: cpufunc.h,v 1.37 2019/10/30 17:06:57 maxv Exp $ */ +/* $NetBSD: cpufunc.h,v 1.37.6.1 2020/04/15 16:04:06 bouyer Exp $ */ /* * Copyright (c) 1998, 2007, 2019 The NetBSD Foundation, Inc. @@ -103,7 +103,7 @@ rdtsc(void) return (low | ((uint64_t)high << 32)); } -#ifndef XEN +#ifndef XENPV void x86_hotpatch(uint32_t, const uint8_t *, size_t); void x86_patch_window_open(u_long *, u_long *); void x86_patch_window_close(u_long, u_long); Index: src/sys/arch/x86/x86/patch.c diff -u src/sys/arch/x86/x86/patch.c:1.37.6.2 src/sys/arch/x86/x86/patch.c:1.37.6.3 --- src/sys/arch/x86/x86/patch.c:1.37.6.2 Tue Apr 14 16:53:57 2020 +++ src/sys/arch/x86/x86/patch.c Wed Apr 15 16:04:06 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: patch.c,v 1.37.6.2 2020/04/14 16:53:57 bouyer Exp $ */ +/* $NetBSD: patch.c,v 1.37.6.3 2020/04/15 16:04:06 bouyer Exp $ */ /*- * Copyright (c) 2007, 2008, 2009 The NetBSD Foundation, Inc. @@ -34,7 +34,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: patch.c,v 1.37.6.2 2020/04/14 16:53:57 bouyer Exp $"); +__KERNEL_RCSID(0, "$NetBSD: patch.c,v 1.37.6.3 2020/04/15 16:04:06 bouyer Exp $"); #include "opt_lockdebug.h" #ifdef i386 @@ -247,7 +247,6 @@ x86_patch(bool early) NULL ); } -#endif /* i386 */ #if !defined(SPLDEBUG) if (!early && (cpu_feature[0] & CPUID_CX8) != 0) { @@ -257,15 +256,16 @@ x86_patch(bool early) spllower, spllower_end, cx8_spllower_patch ); -#if defined(i386) && !defined(LOCKDEBUG) +#if !defined(LOCKDEBUG) patchfunc( i686_mutex_spin_exit, i686_mutex_spin_exit_end, mutex_spin_exit, mutex_spin_exit_end, i686_mutex_spin_exit_patch ); -#endif /* i386 && !LOCKDEBUG */ +#endif /* !LOCKDEBUG */ } #endif /* !SPLDEBUG */ +#endif /* i386 */ /* * On some Opteron revisions, locked operations erroneously