Module Name: src
Committed By: maxv
Date: Fri May 1 08:32:50 UTC 2020
Modified Files:
src/common/lib/libc/arch/i386/atomic: atomic.S
src/sys/arch/i386/include: frameasm.h
src/sys/arch/x86/x86: patch.c
Log Message:
Use the hotpatch framework when patching _atomic_cas_64.
To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/common/lib/libc/arch/i386/atomic/atomic.S
cvs rdiff -u -r1.31 -r1.32 src/sys/arch/i386/include/frameasm.h
cvs rdiff -u -r1.43 -r1.44 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/common/lib/libc/arch/i386/atomic/atomic.S
diff -u src/common/lib/libc/arch/i386/atomic/atomic.S:1.28 src/common/lib/libc/arch/i386/atomic/atomic.S:1.29
--- src/common/lib/libc/arch/i386/atomic/atomic.S:1.28 Sun Apr 26 14:49:17 2020
+++ src/common/lib/libc/arch/i386/atomic/atomic.S Fri May 1 08:32:50 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: atomic.S,v 1.28 2020/04/26 14:49:17 maxv Exp $ */
+/* $NetBSD: atomic.S,v 1.29 2020/05/01 08:32:50 maxv Exp $ */
/*-
* Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -48,12 +48,12 @@
#define LOCK HOTPATCH(HP_NAME_NOLOCK, 1); lock
#define HOTPATCH_SSE2_LFENCE HOTPATCH(HP_NAME_SSE2_LFENCE, 7);
#define HOTPATCH_SSE2_MFENCE HOTPATCH(HP_NAME_SSE2_MFENCE, 7);
-#define ENDLABEL(a) _ALIGN_TEXT; LABEL(a)
+#define HOTPATCH_CAS_64 HOTPATCH(HP_NAME_CAS_64, 49);
#else
#define LOCK lock
#define HOTPATCH_SSE2_LFENCE /* nothing */
#define HOTPATCH_SSE2_MFENCE /* nothing */
-#define ENDLABEL(a) /* nothing */
+#define HOTPATCH_CAS_64 /* nothing */
#endif
.text
@@ -207,10 +207,12 @@ END(_membar_sync)
STRONG_ALIAS(_atomic_cas_64,_atomic_cas_cx8)
#else
ENTRY(_atomic_cas_64)
+ HOTPATCH_CAS_64
+ /* 49 bytes of instructions */
#ifdef _HARDKERNEL
pushf
cli
-#endif /* _HARDKERNEL */
+#endif
pushl %edi
pushl %ebx
movl 12(%esp), %edi
@@ -229,17 +231,17 @@ ENTRY(_atomic_cas_64)
popl %edi
#ifdef _HARDKERNEL
popf
-#endif /* _HARDKERNEL */
+#endif
ret
2:
movl 0(%edi), %eax
movl 4(%edi), %edx
jmp 1b
END(_atomic_cas_64)
-ENDLABEL(_atomic_cas_64_end)
-#endif /* !XEN */
+#endif /* !XENPV */
ENTRY(_atomic_cas_cx8)
+ /* 49 bytes of instructions */
pushl %edi
pushl %ebx
movl 12(%esp), %edi
@@ -253,14 +255,10 @@ ENTRY(_atomic_cas_cx8)
popl %edi
ret
#ifdef _HARDKERNEL
-#ifdef GPROF
- .space 16, 0x90
-#else
- .space 32, 0x90
+ .space 20, 0xCC
#endif
-#endif /* _HARDKERNEL */
END(_atomic_cas_cx8)
-ENDLABEL(_atomic_cas_cx8_end)
+LABEL(_atomic_cas_cx8_end)
#endif /* __HAVE_ATOMIC64_OPS || _KERNEL */
ALIAS(atomic_add_32,_atomic_add_32)
Index: src/sys/arch/i386/include/frameasm.h
diff -u src/sys/arch/i386/include/frameasm.h:1.31 src/sys/arch/i386/include/frameasm.h:1.32
--- src/sys/arch/i386/include/frameasm.h:1.31 Sun Apr 26 14:49:17 2020
+++ src/sys/arch/i386/include/frameasm.h Fri May 1 08:32:50 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: frameasm.h,v 1.31 2020/04/26 14:49:17 maxv Exp $ */
+/* $NetBSD: frameasm.h,v 1.32 2020/05/01 08:32:50 maxv Exp $ */
#ifndef _I386_FRAMEASM_H_
#define _I386_FRAMEASM_H_
@@ -50,6 +50,7 @@
#define HP_NAME_RETFENCE 4
#define HP_NAME_SSE2_LFENCE 5
#define HP_NAME_SSE2_MFENCE 6
+#define HP_NAME_CAS_64 7
#define HOTPATCH(name, size) \
123: ; \
Index: src/sys/arch/x86/x86/patch.c
diff -u src/sys/arch/x86/x86/patch.c:1.43 src/sys/arch/x86/x86/patch.c:1.44
--- src/sys/arch/x86/x86/patch.c:1.43 Thu Apr 30 17:17:33 2020
+++ src/sys/arch/x86/x86/patch.c Fri May 1 08:32:50 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: patch.c,v 1.43 2020/04/30 17:17:33 maxv Exp $ */
+/* $NetBSD: patch.c,v 1.44 2020/05/01 08:32:50 maxv 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.43 2020/04/30 17:17:33 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: patch.c,v 1.44 2020/05/01 08:32:50 maxv Exp $");
#include "opt_lockdebug.h"
#ifdef i386
@@ -69,14 +69,6 @@ void i686_mutex_spin_exit(int);
void i686_mutex_spin_exit_end(void);
void i686_mutex_spin_exit_patch(void);
-void _atomic_cas_64(void);
-void _atomic_cas_64_end(void);
-void _atomic_cas_cx8(void);
-void _atomic_cas_cx8_end(void);
-
-#define X86_NOP 0x90
-#define X86_REP 0xf3
-#define X86_RET 0xc3
#define X86_CS 0x2e
#define X86_DS 0x3e
#define X86_GROUP_0F 0x0f
@@ -229,11 +221,11 @@ x86_patch(bool early)
* may be gone.
*/
if ((cpu_feature[0] & CPUID_CX8) != 0) {
- patchfunc(
- _atomic_cas_cx8, _atomic_cas_cx8_end,
- _atomic_cas_64, _atomic_cas_64_end,
- NULL
- );
+ extern uint8_t _atomic_cas_cx8, _atomic_cas_cx8_end;
+
+ bytes = &_atomic_cas_cx8;
+ size = (size_t)&_atomic_cas_cx8_end - (size_t)&_atomic_cas_cx8;
+ x86_hotpatch(HP_NAME_CAS_64, bytes, size);
}
#if !defined(SPLDEBUG)