Skip to contentSkip to conversation

UML - x86_64 thread fixes

PATCH In review Jeff Dike 2 participants 3 messages Feb 8, 2007 – Feb 22, 2007 User-mode Linux (UML)

lore
Share & tools
lore

Jeff Dike

author
#0 lore raw

PATCH 2/3 UML - x86_64 thread fixes

x86_64 needs some TLS fixes. What was missing was remembering the child thread id during clone and stuffing it into the child during each context switch.

The %fs value is stored separately in the thread structure since the host controls what effect it has on the actual register file. The host also needs to store it in its own thread struct, so we need the value kept outside the register file.

arch_prctl_skas was fixed to call PTRACE_ARCH_PRCTL appropriately. There is some saving and restoring of registers in the ARCH_SET_* cases so that the correct set of registers are changed on the host and restored to the process when it runs again.

--

 arch/um/include/os.h                 |    2 
 arch/um/os-Linux/sys-x86_64/Makefile |    2 
 arch/um/os-Linux/sys-x86_64/prctl.c  |   12 +++++
 arch/um/sys-x86_64/syscalls.c        |   73 ++++++++++++++++++++++++++---------
 arch/um/sys-x86_64/tls.c             |   11 +++--
 include/asm-um/processor-x86_64.h    |    6 +-
 include/asm-um/ptrace-x86_64.h       |    6 --
 7 files changed, 83 insertions(+), 29 deletions(-)
arch/um/include/os.h +2 -0
Index: linux-2.6.18-mm/arch/um/include/os.h
===================================================================
@@ -340,4 +340,6 @@ extern void maybe_sigio_broken(int fd, i
 extern void sig_handler_common_skas(int sig, void *sc_ptr);
 extern void user_signal(int sig, union uml_pt_regs *regs, int pid);
 
+extern int os_arch_prctl(int pid, int code, unsigned long *addr);
+
 #endif
arch/um/os-Linux/sys-x86_64/Makefile +1 -1
Index: linux-2.6.18-mm/arch/um/os-Linux/sys-x86_64/Makefile
===================================================================
@@ -3,7 +3,7 @@
 # Licensed under the GPL
 #
 
-obj-$(CONFIG_MODE_SKAS) = registers.o signal.o
+obj-$(CONFIG_MODE_SKAS) = registers.o prctl.o signal.o
 
 USER_OBJS := $(obj-y)
 
arch/um/os-Linux/sys-x86_64/prctl.c new file +12 -0
Index: linux-2.6.18-mm/arch/um/os-Linux/sys-x86_64/prctl.c
===================================================================
@@ -0,0 +1,12 @@
+/*
+ * Copyright (C) 2007 Jeff Dike (jdike@{addtoit.com,linux.intel.com})
+ * Licensed under the GPL
+ */
+
+#include <sys/ptrace.h>
+#include <linux/ptrace.h>
+
+int os_arch_prctl(int pid, int code, unsigned long *addr)
+{
+        return ptrace(PTRACE_ARCH_PRCTL, pid, (unsigned long) addr, code);
+}
arch/um/sys-x86_64/syscalls.c +55 -18

106 lines not on this page · raw message

include/asm-um/processor-x86_64.h +4 -2
Index: linux-2.6.18-mm/include/asm-um/processor-x86_64.h
===================================================================
@@ -13,6 +13,7 @@
 struct arch_thread {
         unsigned long debugregs[8];
         int debugregs_seq;
+        unsigned long fs;
         struct faultinfo faultinfo;
 };
 
@@ -25,8 +26,9 @@ extern inline void rep_nop(void)
 #define cpu_relax()   rep_nop()
 
 #define INIT_ARCH_THREAD { .debugregs  		= { [ 0 ... 7 ] = 0 }, \
-                           .debugregs_seq	= 0, \
-                           .faultinfo		= { 0, 0, 0 } }
+                           .debugregs_seq	= 0,			       \
+			   .fs			= 0, \
+			   .faultinfo		= { 0, 0, 0 } }
 
 static inline void arch_flush_thread(struct arch_thread *thread)
 {
include/asm-um/ptrace-x86_64.h +2 -4
Index: linux-2.6.18-mm/include/asm-um/ptrace-x86_64.h
===================================================================
@@ -81,9 +81,7 @@ static inline void arch_switch_to_tt(str
 {
 }
 
-static inline void arch_switch_to_skas(struct task_struct *from,
-                                       struct task_struct *to)
-{
-}
+extern void arch_switch_to_skas(struct task_struct *from,
+				struct task_struct *to);
 
 #endif
arch/um/sys-x86_64/tls.c +7 -4
Index: linux-2.6.18-mm/arch/um/sys-x86_64/tls.c
===================================================================
@@ -1,14 +1,17 @@
 #include "linux/sched.h"
 
-void debug_arch_force_load_TLS(void)
-{
-}
-
 void clear_flushed_tls(struct task_struct *task)
 {
 }
 
 int arch_copy_tls(struct task_struct *t)
 {
+	/*
+	 * If CLONE_SETTLS is set, we need to save the thread id
+	 * (which is argument 5, child_tid, of clone) so it can be set
+	 * during context switches.
+	 */
+	t->thread.arch.fs = t->thread.regs.regs.skas.regs[R8 / sizeof(long)];
+
         return 0;
 }

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier. Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
User-mode-linux-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel

#1 lore raw
Quoted 8 lines · Jeff Dike

x86_64 needs some TLS fixes. What was missing was remembering the child thread id during clone and stuffing it into the child during each context switch.

The %fs value is stored separately in the thread structure since the host controls what effect it has on the actual register file. The host also needs to store it in its own thread struct, so we need the value kept outside the register file.

Is there any reason for avoiding this treatment to %gs, apart that TLS code usually does not need it, even if the API allows for it to exist? I _do_ believe this patch fixes bug which can be tested (not verified everything), even if I wonder why you didn't look at the patch I sent to you time ago (I hadn't finished it, in truth, but there was most stuff - it had problems I couldn't debug at that time).

Signature · 5 lines
Inform me of my mistakes, so I can add them to my list!
Paolo Giarrusso, aka Blaisorblade
http://www.user-mode-linux.org/~blaisorblade
Chiacchiera con i tuoi amici in tempo reale! 
 http://it.yahoo.com/mail_it/foot/*http://it.messenger.yahoo.com 
author
#2 lore raw
Quoted 2 lines · Blaisorblade

Is there any reason for avoiding this treatment to %gs, apart that TLS code usually does not need it, even if the API allows for it to exist?

Is there any prospect that %gs will be getting similar treatment? %fs is set through CLONE_SETTLS, so it would seem that something like a new clone flag would be required for this.

Quoted 5 lines

I _do_
believe this patch fixes bug which can be tested (not verified everything), even if I wonder why you didn't look at the patch I sent to you time ago (I hadn't finished it, in truth, but there was most stuff - it had problems I couldn't debug at that time).

Maybe because I forgot about it - do you have a pointer?

Jeff

Signature · 11 lines
Work email - jdike at linux dot intel dot com

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
User-mode-linux-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel