Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

fork: move the real prepare_to_copy() users to arch_dup_task_struct()

Historical prepare_to_copy() is mostly a no-op, duplicated for majority of
the architectures and the rest following the x86 model of flushing the extended
register state like fpu there.

Remove it and use the arch_dup_task_struct() instead.

Suggested-by: Oleg Nesterov <oleg@redhat.com>
Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Suresh Siddha <suresh.b.siddha@intel.com>
Link: http://lkml.kernel.org/r/1336692811-30576-1-git-send-email-suresh.b.siddha@intel.com
Acked-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: David Howells <dhowells@redhat.com>
Cc: Koichi Yasutake <yasutake.koichi@jp.panasonic.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Paul Mundt <lethal@linux-sh.org>
Cc: Chris Zankel <chris@zankel.net>
Cc: Richard Henderson <rth@twiddle.net>
Cc: Russell King <linux@arm.linux.org.uk>
Cc: Haavard Skinnemoen <hskinnemoen@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>
Cc: Mark Salter <msalter@redhat.com>
Cc: Aurelien Jacquiot <a-jacquiot@ti.com>
Cc: Mikael Starvik <starvik@axis.com>
Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
Cc: Richard Kuo <rkuo@codeaurora.org>
Cc: Tony Luck <tony.luck@intel.com>
Cc: Michal Simek <monstr@monstr.eu>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: Jonas Bonn <jonas@southpole.se>
Cc: James E.J. Bottomley <jejb@parisc-linux.org>
Cc: Helge Deller <deller@gmx.de>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Chen Liqin <liqin.chen@sunplusct.com>
Cc: Lennox Wu <lennox.wu@gmail.com>
Cc: David S. Miller <davem@davemloft.net>
Cc: Chris Metcalf <cmetcalf@tilera.com>
Cc: Jeff Dike <jdike@addtoit.com>
Cc: Richard Weinberger <richard@nod.at>
Cc: Guan Xuetao <gxt@mprc.pku.edu.cn>
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>

authored by

Suresh Siddha and committed by
H. Peter Anvin
55ccf3fe 36be5051

+36 -140
-3
arch/alpha/include/asm/processor.h
··· 49 49 /* Free all resources held by a thread. */ 50 50 extern void release_thread(struct task_struct *); 51 51 52 - /* Prepare to copy thread state - unlazy all lazy status */ 53 - #define prepare_to_copy(tsk) do { } while (0) 54 - 55 52 /* Create a kernel thread without removing it from tasklists. */ 56 53 extern long kernel_thread(int (*fn)(void *), void *arg, unsigned long flags); 57 54
-3
arch/arm/include/asm/processor.h
··· 77 77 /* Free all resources held by a thread. */ 78 78 extern void release_thread(struct task_struct *); 79 79 80 - /* Prepare to copy thread state - unlazy all lazy status */ 81 - #define prepare_to_copy(tsk) do { } while (0) 82 - 83 80 unsigned long get_wchan(struct task_struct *p); 84 81 85 82 #if __LINUX_ARM_ARCH__ == 6 || defined(CONFIG_ARM_ERRATA_754327)
-3
arch/avr32/include/asm/processor.h
··· 145 145 /* Create a kernel thread without removing it from tasklists */ 146 146 extern int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags); 147 147 148 - /* Prepare to copy thread state - unlazy all lazy status */ 149 - #define prepare_to_copy(tsk) do { } while(0) 150 - 151 148 /* Return saved PC of a blocked thread */ 152 149 #define thread_saved_pc(tsk) ((tsk)->thread.cpu_context.pc) 153 150
-2
arch/blackfin/include/asm/processor.h
··· 75 75 { 76 76 } 77 77 78 - #define prepare_to_copy(tsk) do { } while (0) 79 - 80 78 extern int kernel_thread(int (*fn) (void *), void *arg, unsigned long flags); 81 79 82 80 /*
-3
arch/c6x/include/asm/processor.h
··· 92 92 { 93 93 } 94 94 95 - /* Prepare to copy thread state - unlazy all lazy status */ 96 - #define prepare_to_copy(tsk) do { } while (0) 97 - 98 95 extern int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags); 99 96 100 97 #define copy_segments(tsk, mm) do { } while (0)
-4
arch/cris/include/asm/processor.h
··· 50 50 #define task_pt_regs(task) user_regs(task_thread_info(task)) 51 51 #define current_regs() task_pt_regs(current) 52 52 53 - static inline void prepare_to_copy(struct task_struct *tsk) 54 - { 55 - } 56 - 57 53 extern int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags); 58 54 59 55 unsigned long get_wchan(struct task_struct *p);
-2
arch/frv/include/asm/processor.h
··· 103 103 __frame->sp = (_usp); \ 104 104 } while(0) 105 105 106 - extern void prepare_to_copy(struct task_struct *tsk); 107 - 108 106 /* Free all resources held by a thread. */ 109 107 static inline void release_thread(struct task_struct *dead_task) 110 108 {
-11
arch/frv/kernel/process.c
··· 180 180 return do_fork(clone_flags, newsp, __frame, 0, parent_tidptr, child_tidptr); 181 181 } /* end sys_clone() */ 182 182 183 - /*****************************************************************************/ 184 - /* 185 - * This gets called before we allocate a new thread and copy 186 - * the current task into it. 187 - */ 188 - void prepare_to_copy(struct task_struct *tsk) 189 - { 190 - //unlazy_fpu(tsk); 191 - } /* end prepare_to_copy() */ 192 - 193 - /*****************************************************************************/ 194 183 /* 195 184 * set up the kernel stack and exception frames for a new process 196 185 */
-2
arch/h8300/include/asm/processor.h
··· 109 109 110 110 extern int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags); 111 111 112 - #define prepare_to_copy(tsk) do { } while (0) 113 - 114 112 /* 115 113 * Free current thread data structures etc.. 116 114 */
-7
arch/hexagon/include/asm/processor.h
··· 59 59 #define cpu_relax() __vmyield() 60 60 61 61 /* 62 - * "Unlazying all lazy status" occurs here. 63 - */ 64 - static inline void prepare_to_copy(struct task_struct *tsk) 65 - { 66 - } 67 - 68 - /* 69 62 * Decides where the kernel will search for a free chunk of vm space during 70 63 * mmaps. 71 64 * See also arch_get_unmapped_area.
-3
arch/ia64/include/asm/processor.h
··· 343 343 */ 344 344 #define release_thread(dead_task) 345 345 346 - /* Prepare to copy thread state - unlazy all lazy status */ 347 - #define prepare_to_copy(tsk) do { } while (0) 348 - 349 346 /* 350 347 * This is the mechanism for creating a new kernel thread. 351 348 *
-2
arch/m32r/include/asm/processor.h
··· 118 118 /* Free all resources held by a thread. */ 119 119 extern void release_thread(struct task_struct *); 120 120 121 - #define prepare_to_copy(tsk) do { } while (0) 122 - 123 121 /* 124 122 * create a kernel thread without removing it from tasklists 125 123 */
-3
arch/m68k/include/asm/processor.h
··· 153 153 { 154 154 } 155 155 156 - /* Prepare to copy thread state - unlazy all lazy status */ 157 - #define prepare_to_copy(tsk) do { } while (0) 158 - 159 156 extern int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags); 160 157 161 158 /*
-1
arch/microblaze/include/asm/processor.h
··· 23 23 24 24 # define cpu_relax() barrier() 25 25 # define cpu_sleep() do {} while (0) 26 - # define prepare_to_copy(tsk) do {} while (0) 27 26 28 27 #define task_pt_regs(tsk) \ 29 28 (((struct pt_regs *)(THREAD_SIZE + task_stack_page(tsk))) - 1)
-3
arch/mips/include/asm/processor.h
··· 310 310 /* Free all resources held by a thread. */ 311 311 #define release_thread(thread) do { } while(0) 312 312 313 - /* Prepare to copy thread state - unlazy all lazy status */ 314 - #define prepare_to_copy(tsk) do { } while (0) 315 - 316 313 extern long kernel_thread(int (*fn)(void *), void * arg, unsigned long flags); 317 314 318 315 extern unsigned long thread_saved_pc(struct task_struct *tsk);
-3
arch/mn10300/include/asm/processor.h
··· 139 139 /* Free all resources held by a thread. */ 140 140 extern void release_thread(struct task_struct *); 141 141 142 - /* Prepare to copy thread state - unlazy all lazy status */ 143 - extern void prepare_to_copy(struct task_struct *tsk); 144 - 145 142 /* 146 143 * create a kernel thread without removing it from tasklists 147 144 */
+6 -4
arch/mn10300/kernel/process.c
··· 208 208 } 209 209 210 210 /* 211 - * this gets called before we allocate a new thread and copy the current task 212 - * into it so that we can store lazy state into memory 211 + * this gets called so that we can store lazy state into memory and copy the 212 + * current task into the new thread. 213 213 */ 214 - void prepare_to_copy(struct task_struct *tsk) 214 + int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src) 215 215 { 216 - unlazy_fpu(tsk); 216 + unlazy_fpu(src); 217 + *dst = *src; 218 + return 0; 217 219 } 218 220 219 221 /*
-4
arch/openrisc/include/asm/processor.h
··· 72 72 #define task_pt_regs(task) user_regs(task_thread_info(task)) 73 73 #define current_regs() user_regs(current_thread_info()) 74 74 75 - extern inline void prepare_to_copy(struct task_struct *tsk) 76 - { 77 - } 78 - 79 75 #define INIT_SP (sizeof(init_stack) + (unsigned long) &init_stack) 80 76 81 77 #define INIT_THREAD { }
-3
arch/parisc/include/asm/processor.h
··· 328 328 extern void release_thread(struct task_struct *); 329 329 extern int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags); 330 330 331 - /* Prepare to copy thread state - unlazy all lazy status */ 332 - #define prepare_to_copy(tsk) do { } while (0) 333 - 334 331 extern void map_hpux_gateway_page(struct task_struct *tsk, struct mm_struct *mm); 335 332 336 333 extern unsigned long get_wchan(struct task_struct *p);
-3
arch/powerpc/include/asm/processor.h
··· 74 74 void start_thread(struct pt_regs *regs, unsigned long fdptr, unsigned long sp); 75 75 void release_thread(struct task_struct *); 76 76 77 - /* Prepare to copy thread state - unlazy all lazy status */ 78 - extern void prepare_to_copy(struct task_struct *tsk); 79 - 80 77 /* Create a new kernel thread. */ 81 78 extern long kernel_thread(int (*fn)(void *), void *arg, unsigned long flags); 82 79
+11 -8
arch/powerpc/kernel/process.c
··· 711 711 } 712 712 713 713 /* 714 - * This gets called before we allocate a new thread and copy 715 - * the current task into it. 714 + * this gets called so that we can store coprocessor state into memory and 715 + * copy the current task into the new thread. 716 716 */ 717 - void prepare_to_copy(struct task_struct *tsk) 717 + int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src) 718 718 { 719 - flush_fp_to_thread(current); 720 - flush_altivec_to_thread(current); 721 - flush_vsx_to_thread(current); 722 - flush_spe_to_thread(current); 719 + flush_fp_to_thread(src); 720 + flush_altivec_to_thread(src); 721 + flush_vsx_to_thread(src); 722 + flush_spe_to_thread(src); 723 723 #ifdef CONFIG_HAVE_HW_BREAKPOINT 724 - flush_ptrace_hw_breakpoint(tsk); 724 + flush_ptrace_hw_breakpoint(src); 725 725 #endif /* CONFIG_HAVE_HW_BREAKPOINT */ 726 + 727 + *dst = *src; 728 + return 0; 726 729 } 727 730 728 731 /*
-3
arch/s390/include/asm/processor.h
··· 141 141 extern void release_thread(struct task_struct *); 142 142 extern int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags); 143 143 144 - /* Prepare to copy thread state - unlazy all lazy status */ 145 - #define prepare_to_copy(tsk) do { } while (0) 146 - 147 144 /* 148 145 * Return saved PC of a blocked thread. 149 146 */
-1
arch/score/include/asm/processor.h
··· 26 26 27 27 #define cpu_relax() barrier() 28 28 #define release_thread(thread) do {} while (0) 29 - #define prepare_to_copy(tsk) do {} while (0) 30 29 31 30 /* 32 31 * User space process size: 2GB. This is hardcoded into a few places,
-3
arch/sh/include/asm/processor_32.h
··· 126 126 /* Free all resources held by a thread. */ 127 127 extern void release_thread(struct task_struct *); 128 128 129 - /* Prepare to copy thread state - unlazy all lazy status */ 130 - void prepare_to_copy(struct task_struct *tsk); 131 - 132 129 /* 133 130 * create a kernel thread without removing it from tasklists 134 131 */
-1
arch/sh/include/asm/processor_64.h
··· 172 172 #define copy_segments(p, mm) do { } while (0) 173 173 #define release_segments(mm) do { } while (0) 174 174 #define forget_segments() do { } while (0) 175 - #define prepare_to_copy(tsk) do { } while (0) 176 175 /* 177 176 * FPU lazy state save handling. 178 177 */
+7
arch/sh/kernel/process.c
··· 6 6 struct kmem_cache *task_xstate_cachep = NULL; 7 7 unsigned int xstate_size; 8 8 9 + /* 10 + * this gets called so that we can store lazy state into memory and copy the 11 + * current task into the new thread. 12 + */ 9 13 int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src) 10 14 { 15 + #ifdef CONFIG_SUPERH32 16 + unlazy_fpu(src, task_pt_regs(src)); 17 + #endif 11 18 *dst = *src; 12 19 13 20 if (src->thread.xstate) {
-9
arch/sh/kernel/process_32.c
··· 155 155 } 156 156 EXPORT_SYMBOL(dump_fpu); 157 157 158 - /* 159 - * This gets called before we allocate a new thread and copy 160 - * the current task into it. 161 - */ 162 - void prepare_to_copy(struct task_struct *tsk) 163 - { 164 - unlazy_fpu(tsk, task_pt_regs(tsk)); 165 - } 166 - 167 158 asmlinkage void ret_from_fork(void); 168 159 169 160 int copy_thread(unsigned long clone_flags, unsigned long usp,
-3
arch/sparc/include/asm/processor_32.h
··· 109 109 #define release_thread(tsk) do { } while(0) 110 110 extern pid_t kernel_thread(int (*fn)(void *), void * arg, unsigned long flags); 111 111 112 - /* Prepare to copy thread state - unlazy all lazy status */ 113 - #define prepare_to_copy(tsk) do { } while (0) 114 - 115 112 extern unsigned long get_wchan(struct task_struct *); 116 113 117 114 #define task_pt_regs(tsk) ((tsk)->thread.kregs)
-3
arch/sparc/include/asm/processor_64.h
··· 186 186 /* Free all resources held by a thread. */ 187 187 #define release_thread(tsk) do { } while (0) 188 188 189 - /* Prepare to copy thread state - unlazy all lazy status */ 190 - #define prepare_to_copy(tsk) do { } while (0) 191 - 192 189 extern pid_t kernel_thread(int (*fn)(void *), void * arg, unsigned long flags); 193 190 194 191 extern unsigned long get_wchan(struct task_struct *task);
-3
arch/tile/include/asm/processor.h
··· 210 210 /* Nothing for now */ 211 211 } 212 212 213 - /* Prepare to copy thread state - unlazy all lazy status. */ 214 - #define prepare_to_copy(tsk) do { } while (0) 215 - 216 213 extern int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags); 217 214 218 215 extern int do_work_pending(struct pt_regs *regs, u32 flags);
-5
arch/um/include/asm/processor-generic.h
··· 76 76 77 77 extern int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags); 78 78 79 - static inline void prepare_to_copy(struct task_struct *tsk) 80 - { 81 - } 82 - 83 - 84 79 extern unsigned long thread_saved_pc(struct task_struct *t); 85 80 86 81 static inline void mm_copy_segments(struct mm_struct *from_mm,
-3
arch/unicore32/include/asm/processor.h
··· 68 68 /* Free all resources held by a thread. */ 69 69 extern void release_thread(struct task_struct *); 70 70 71 - /* Prepare to copy thread state - unlazy all lazy status */ 72 - #define prepare_to_copy(tsk) do { } while (0) 73 - 74 71 unsigned long get_wchan(struct task_struct *p); 75 72 76 73 #define cpu_relax() barrier()
-3
arch/x86/include/asm/processor.h
··· 579 579 /* Free all resources held by a thread. */ 580 580 extern void release_thread(struct task_struct *); 581 581 582 - /* Prepare to copy thread state - unlazy all lazy state */ 583 - extern void prepare_to_copy(struct task_struct *tsk); 584 - 585 582 unsigned long get_wchan(struct task_struct *p); 586 583 587 584 /*
+6
arch/x86/kernel/process.c
··· 47 47 struct kmem_cache *task_xstate_cachep; 48 48 EXPORT_SYMBOL_GPL(task_xstate_cachep); 49 49 50 + /* 51 + * this gets called so that we can store lazy state into memory and copy the 52 + * current task into the new thread. 53 + */ 50 54 int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src) 51 55 { 52 56 int ret; 57 + 58 + unlazy_fpu(src); 53 59 54 60 *dst = *src; 55 61 if (fpu_allocated(&src->thread.fpu)) {
-9
arch/x86/kernel/process_32.c
··· 126 126 release_vm86_irqs(dead_task); 127 127 } 128 128 129 - /* 130 - * This gets called before we allocate a new thread and copy 131 - * the current task into it. 132 - */ 133 - void prepare_to_copy(struct task_struct *tsk) 134 - { 135 - unlazy_fpu(tsk); 136 - } 137 - 138 129 int copy_thread(unsigned long clone_flags, unsigned long sp, 139 130 unsigned long unused, 140 131 struct task_struct *p, struct pt_regs *regs)
-9
arch/x86/kernel/process_64.c
··· 145 145 return get_desc_base(&t->thread.tls_array[tls]); 146 146 } 147 147 148 - /* 149 - * This gets called before we allocate a new thread and copy 150 - * the current task into it. 151 - */ 152 - void prepare_to_copy(struct task_struct *tsk) 153 - { 154 - unlazy_fpu(tsk); 155 - } 156 - 157 148 int copy_thread(unsigned long clone_flags, unsigned long sp, 158 149 unsigned long unused, 159 150 struct task_struct *p, struct pt_regs *regs)
-3
arch/xtensa/include/asm/processor.h
··· 168 168 /* Free all resources held by a thread. */ 169 169 #define release_thread(thread) do { } while(0) 170 170 171 - /* Prepare to copy thread state - unlazy all lazy status */ 172 - extern void prepare_to_copy(struct task_struct*); 173 - 174 171 /* Create a kernel thread without removing it from tasklists */ 175 172 extern int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags); 176 173
+6 -3
arch/xtensa/kernel/process.c
··· 140 140 } 141 141 142 142 /* 143 - * This is called before the thread is copied. 143 + * this gets called so that we can store coprocessor state into memory and 144 + * copy the current task into the new thread. 144 145 */ 145 - void prepare_to_copy(struct task_struct *tsk) 146 + int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src) 146 147 { 147 148 #if XTENSA_HAVE_COPROCESSORS 148 - coprocessor_flush_all(task_thread_info(tsk)); 149 + coprocessor_flush_all(task_thread_info(src)); 149 150 #endif 151 + *dst = *src; 152 + return 0; 150 153 } 151 154 152 155 /*
-2
kernel/fork.c
··· 261 261 int node = tsk_fork_get_node(orig); 262 262 int err; 263 263 264 - prepare_to_copy(orig); 265 - 266 264 tsk = alloc_task_struct_node(node); 267 265 if (!tsk) 268 266 return NULL;