Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/powerpc Fix inconsistency b/w kernel and userland r...



details:   https://anonhg.NetBSD.org/src/rev/a6190abd2b6c
branches:  trunk
changeset: 934959:a6190abd2b6c
user:      rin <rin%NetBSD.org@localhost>
date:      Sun Jun 21 00:39:59 2020 +0000

description:
Fix inconsistency b/w kernel and userland recognitions of TLS, as well as
inconsistency whether it is biased or not in kernel.

- Obsolete __lwp_settcb() in order to let kernel know new TLS address via
  _lwp_setprivate(2). Alternatively, we can call _lwp_setprivate(2) within
  __lwp_settcb() like mips, but it is just double handling; we adjust %r2
  appropriately in _lwp_setprivate(2) via cpu_lwp_setprivate().

- Make sure that, like other ports, l_private represents address of tcb,
  not biased one as in %r2. This guarantees that the returned values from
  _lwp_getprivate(2) and __lwp_getprivate_fast() are always same. Also,
  we can obsolete PTRACE_LWP_GETPRIVATE() macro.

Now, *_pl_private tests in tests/lib/libc/sys successfully pass, while
no other tests become newly falling.

diffstat:

 sys/arch/powerpc/include/mcontext.h    |  19 ++++++-------------
 sys/arch/powerpc/include/ptrace.h      |   6 +-----
 sys/arch/powerpc/include/types.h       |   3 +--
 sys/arch/powerpc/powerpc/sig_machdep.c |  11 +++++++----
 4 files changed, 15 insertions(+), 24 deletions(-)

diffs (120 lines):

diff -r 6b74f26a5660 -r a6190abd2b6c sys/arch/powerpc/include/mcontext.h
--- a/sys/arch/powerpc/include/mcontext.h       Sun Jun 21 00:00:27 2020 +0000
+++ b/sys/arch/powerpc/include/mcontext.h       Sun Jun 21 00:39:59 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mcontext.h,v 1.19 2020/06/21 00:00:27 rin Exp $        */
+/*     $NetBSD: mcontext.h,v 1.20 2020/06/21 00:39:59 rin Exp $        */
 
 /*-
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -141,7 +141,8 @@
 
 #define        _UC_MACHINE_SET_PC(uc, pc)      _UC_MACHINE_PC(uc) = (pc)
 
-#if defined(_RTLD_SOURCE) || defined(_LIBC_SOURCE) || defined(__LIBPTHREAD_SOURCE__)
+#if defined(_KERNEL) || \
+defined(_RTLD_SOURCE) || defined(_LIBC_SOURCE) || defined(__LIBPTHREAD_SOURCE__)
 #include <sys/tls.h>
 
 /*
@@ -153,6 +154,7 @@
 #define        TLS_DTV_OFFSET  0x8000
 __CTASSERT(TLS_TP_OFFSET + sizeof(struct tls_tcb) < 0x8000);
 
+#ifndef _KERNEL
 static __inline void *
 __lwp_gettcb_fast(void)
 {
@@ -165,16 +167,7 @@
 
        return __tcb;
 }
-
-static __inline void
-__lwp_settcb(void *__tcb)
-{
-       __asm __volatile(
-               "addi %%r2,%[__tcb],%[__offset]"
-           :
-           :   [__tcb] "r" (__tcb),
-               [__offset] "n" (TLS_TP_OFFSET + sizeof(struct tls_tcb)));
-}
-#endif /* _RTLD_SOURCE || _LIBC_SOURCE || __LIBPTHREAD_SOURCE__ */
+#endif /* !_KERNEL */
+#endif /* _KERNEL || _RTLD_SOURCE || _LIBC_SOURCE || __LIBPTHREAD_SOURCE__ */
 
 #endif /* !_POWERPC_MCONTEXT_H_ */
diff -r 6b74f26a5660 -r a6190abd2b6c sys/arch/powerpc/include/ptrace.h
--- a/sys/arch/powerpc/include/ptrace.h Sun Jun 21 00:00:27 2020 +0000
+++ b/sys/arch/powerpc/include/ptrace.h Sun Jun 21 00:39:59 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ptrace.h,v 1.16 2019/12/24 14:50:59 kamil Exp $        */
+/*     $NetBSD: ptrace.h,v 1.17 2020/06/21 00:39:59 rin Exp $  */
 
 #ifndef _POWERPC_PTRACE_H
 #define        _POWERPC_PTRACE_H
@@ -77,8 +77,4 @@
 #define PTRACE_BREAKPOINT_ASM  __asm __volatile("trap")
 #define PTRACE_BREAKPOINT_SIZE 4
 
-#ifdef _KERNEL
-#define PTRACE_LWP_GETPRIVATE(l) (l)->l_md.md_utf->tf_fixreg[_REG_R2]
-#endif
-
 #endif /* _POWERPC_PTRACE_H */
diff -r 6b74f26a5660 -r a6190abd2b6c sys/arch/powerpc/include/types.h
--- a/sys/arch/powerpc/include/types.h  Sun Jun 21 00:00:27 2020 +0000
+++ b/sys/arch/powerpc/include/types.h  Sun Jun 21 00:39:59 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: types.h,v 1.62 2020/04/16 22:11:12 rin Exp $   */
+/*     $NetBSD: types.h,v 1.63 2020/06/21 00:39:59 rin Exp $   */
 
 /*-
  * Copyright (C) 1995 Wolfgang Solfrank.
@@ -89,7 +89,6 @@
 #define        __HAVE_CPU_LWP_SETPRIVATE
 #define        __HAVE_COMMON___TLS_GET_ADDR
 #define        __HAVE___LWP_GETTCB_FAST
-#define        __HAVE___LWP_SETTCB
 #define        __HAVE_TLS_VARIANT_I
 
 #if defined(_KERNEL) || defined(_KMEMUSER)
diff -r 6b74f26a5660 -r a6190abd2b6c sys/arch/powerpc/powerpc/sig_machdep.c
--- a/sys/arch/powerpc/powerpc/sig_machdep.c    Sun Jun 21 00:00:27 2020 +0000
+++ b/sys/arch/powerpc/powerpc/sig_machdep.c    Sun Jun 21 00:39:59 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sig_machdep.c,v 1.49 2020/06/21 00:00:27 rin Exp $     */
+/*     $NetBSD: sig_machdep.c,v 1.50 2020/06/21 00:40:00 rin Exp $     */
 
 /*
  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sig_machdep.c,v 1.49 2020/06/21 00:00:27 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sig_machdep.c,v 1.50 2020/06/21 00:40:00 rin Exp $");
 
 #include "opt_ppcarch.h"
 #include "opt_altivec.h"
@@ -243,8 +243,9 @@
 #endif
        }
 
+#define TLS_BIAS (TLS_TP_OFFSET + sizeof(struct tls_tcb))
        if (flags & _UC_TLSBASE)
-               lwp_setprivate(l, (void *)(uintptr_t)gr[_REG_R2]);
+               lwp_setprivate(l, (void *)((uintptr_t)gr[_REG_R2] - TLS_BIAS));
 
 #ifdef PPC_HAVE_FPU
        /* Restore FPU context, if any. */
@@ -279,6 +280,8 @@
 {
        struct trapframe * const tf = l->l_md.md_utf;
 
-       tf->tf_fixreg[_REG_R2] = (register_t)addr;
+       tf->tf_fixreg[_REG_R2] = (register_t)addr + TLS_BIAS;
+#undef TLS_BIAS
+
        return 0;
 }



Home | Main Index | Thread Index | Old Index