Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/x86/x86 Use the hotpatch framework when patching _a...



details:   https://anonhg.NetBSD.org/src/rev/33ef8fce5a15
branches:  trunk
changeset: 971676:33ef8fce5a15
user:      maxv <maxv%NetBSD.org@localhost>
date:      Fri May 01 08:32:50 2020 +0000

description:
Use the hotpatch framework when patching _atomic_cas_64.

diffstat:

 common/lib/libc/arch/i386/atomic/atomic.S |  24 +++++++++++-------------
 sys/arch/i386/include/frameasm.h          |   3 ++-
 sys/arch/x86/x86/patch.c                  |  22 +++++++---------------
 3 files changed, 20 insertions(+), 29 deletions(-)

diffs (143 lines):

diff -r a917ab680015 -r 33ef8fce5a15 common/lib/libc/arch/i386/atomic/atomic.S
--- a/common/lib/libc/arch/i386/atomic/atomic.S Fri May 01 08:21:27 2020 +0000
+++ b/common/lib/libc/arch/i386/atomic/atomic.S Fri May 01 08:32:50 2020 +0000
@@ -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 @@
 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 @@
        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 @@
        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)
diff -r a917ab680015 -r 33ef8fce5a15 sys/arch/i386/include/frameasm.h
--- a/sys/arch/i386/include/frameasm.h  Fri May 01 08:21:27 2020 +0000
+++ b/sys/arch/i386/include/frameasm.h  Fri May 01 08:32:50 2020 +0000
@@ -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:                                           ; \
diff -r a917ab680015 -r 33ef8fce5a15 sys/arch/x86/x86/patch.c
--- a/sys/arch/x86/x86/patch.c  Fri May 01 08:21:27 2020 +0000
+++ b/sys/arch/x86/x86/patch.c  Fri May 01 08:32:50 2020 +0000
@@ -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_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 @@
         * 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)



Home | Main Index | Thread Index | Old Index