Skip to content

Commit e646469

Browse files
Jiri Slabytorvalds
authored andcommitted
exit_thread: accept a task parameter to be exited
We need to call exit_thread from copy_process in a fail path. So make it accept task_struct as a parameter. [v2] * s390: exit_thread_runtime_instr doesn't make sense to be called for non-current tasks. * arm: fix the comment in vfp_thread_copy * change 'me' to 'tsk' for task_struct * now we can change only archs that actually have exit_thread [[email protected]: coding-style fixes] Signed-off-by: Jiri Slaby <[email protected]> Cc: "David S. Miller" <[email protected]> Cc: "H. Peter Anvin" <[email protected]> Cc: "James E.J. Bottomley" <[email protected]> Cc: Aurelien Jacquiot <[email protected]> Cc: Benjamin Herrenschmidt <[email protected]> Cc: Catalin Marinas <[email protected]> Cc: Chen Liqin <[email protected]> Cc: Chris Metcalf <[email protected]> Cc: Chris Zankel <[email protected]> Cc: David Howells <[email protected]> Cc: Fenghua Yu <[email protected]> Cc: Geert Uytterhoeven <[email protected]> Cc: Guan Xuetao <[email protected]> Cc: Haavard Skinnemoen <[email protected]> Cc: Hans-Christian Egtvedt <[email protected]> Cc: Heiko Carstens <[email protected]> Cc: Helge Deller <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Ivan Kokshaysky <[email protected]> Cc: James Hogan <[email protected]> Cc: Jeff Dike <[email protected]> Cc: Jesper Nilsson <[email protected]> Cc: Jiri Slaby <[email protected]> Cc: Jonas Bonn <[email protected]> Cc: Koichi Yasutake <[email protected]> Cc: Lennox Wu <[email protected]> Cc: Ley Foon Tan <[email protected]> Cc: Mark Salter <[email protected]> Cc: Martin Schwidefsky <[email protected]> Cc: Matt Turner <[email protected]> Cc: Max Filippov <[email protected]> Cc: Michael Ellerman <[email protected]> Cc: Michal Simek <[email protected]> Cc: Mikael Starvik <[email protected]> Cc: Paul Mackerras <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Ralf Baechle <[email protected]> Cc: Rich Felker <[email protected]> Cc: Richard Henderson <[email protected]> Cc: Richard Kuo <[email protected]> Cc: Richard Weinberger <[email protected]> Cc: Russell King <[email protected]> Cc: Steven Miao <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Tony Luck <[email protected]> Cc: Vineet Gupta <[email protected]> Cc: Will Deacon <[email protected]> Cc: Yoshinori Sato <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 5f56a5d commit e646469

File tree

17 files changed

+42
-47
lines changed

17 files changed

+42
-47
lines changed

arch/arm/kernel/process.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,9 @@ EXPORT_SYMBOL_GPL(thread_notify_head);
193193
/*
194194
* Free current thread data structures etc..
195195
*/
196-
void exit_thread(void)
196+
void exit_thread(struct task_struct *tsk)
197197
{
198-
thread_notify(THREAD_NOTIFY_EXIT, current_thread_info());
198+
thread_notify(THREAD_NOTIFY_EXIT, task_thread_info(tsk));
199199
}
200200

201201
void flush_thread(void)

arch/arm/vfp/vfpmodule.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,6 @@ static void vfp_thread_copy(struct thread_info *thread)
156156
* - we could be preempted if tree preempt rcu is enabled, so
157157
* it is unsafe to use thread->cpu.
158158
* THREAD_NOTIFY_EXIT
159-
* - the thread (v) will be running on the local CPU, so
160-
* v === current_thread_info()
161-
* - thread->cpu is the local CPU number at the time it is accessed,
162-
* but may change at any time.
163159
* - we could be preempted if tree preempt rcu is enabled, so
164160
* it is unsafe to use thread->cpu.
165161
*/

arch/avr32/kernel/process.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ void machine_restart(char *cmd)
6262
/*
6363
* Free current thread data structures etc
6464
*/
65-
void exit_thread(void)
65+
void exit_thread(struct task_struct *tsk)
6666
{
67-
ocd_disable(current);
67+
ocd_disable(tsk);
6868
}
6969

7070
void flush_thread(void)

arch/cris/arch-v32/kernel/process.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ void default_idle(void)
3333
*/
3434

3535
extern void deconfigure_bp(long pid);
36-
void exit_thread(void)
36+
void exit_thread(struct task_struct *tsk)
3737
{
38-
deconfigure_bp(current->pid);
38+
deconfigure_bp(tsk->pid);
3939
}
4040

4141
/*

arch/ia64/kernel/perfmon.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4542,8 +4542,8 @@ pfm_context_unload(pfm_context_t *ctx, void *arg, int count, struct pt_regs *reg
45424542

45434543

45444544
/*
4545-
* called only from exit_thread(): task == current
4546-
* we come here only if current has a context attached (loaded or masked)
4545+
* called only from exit_thread()
4546+
* we come here only if the task has a context attached (loaded or masked)
45474547
*/
45484548
void
45494549
pfm_exit_thread(struct task_struct *task)

arch/ia64/kernel/process.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -570,22 +570,22 @@ flush_thread (void)
570570
}
571571

572572
/*
573-
* Clean up state associated with current thread. This is called when
573+
* Clean up state associated with a thread. This is called when
574574
* the thread calls exit().
575575
*/
576576
void
577-
exit_thread (void)
577+
exit_thread (struct task_struct *tsk)
578578
{
579579

580-
ia64_drop_fpu(current);
580+
ia64_drop_fpu(tsk);
581581
#ifdef CONFIG_PERFMON
582582
/* if needed, stop monitoring and flush state to perfmon context */
583-
if (current->thread.pfm_context)
584-
pfm_exit_thread(current);
583+
if (tsk->thread.pfm_context)
584+
pfm_exit_thread(tsk);
585585

586586
/* free debug register resources */
587-
if (current->thread.flags & IA64_THREAD_DBG_VALID)
588-
pfm_release_debug_registers(current);
587+
if (tsk->thread.flags & IA64_THREAD_DBG_VALID)
588+
pfm_release_debug_registers(tsk);
589589
#endif
590590
}
591591

arch/metag/kernel/process.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -345,10 +345,10 @@ void flush_thread(void)
345345
/*
346346
* Free current thread data structures etc.
347347
*/
348-
void exit_thread(void)
348+
void exit_thread(struct task_struct *tsk)
349349
{
350-
clear_fpu(&current->thread);
351-
clear_dsp(&current->thread);
350+
clear_fpu(&tsk->thread);
351+
clear_dsp(&tsk->thread);
352352
}
353353

354354
/* TODO: figure out how to unwind the kernel stack here to figure out

arch/mn10300/kernel/process.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ void show_regs(struct pt_regs *regs)
103103
/*
104104
* free current thread data structures etc..
105105
*/
106-
void exit_thread(void)
106+
void exit_thread(struct task_struct *tsk)
107107
{
108-
exit_fpu(current);
108+
exit_fpu(tsk);
109109
}
110110

111111
void flush_thread(void)

arch/s390/kernel/process.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,10 @@ extern void kernel_thread_starter(void);
6868
/*
6969
* Free current thread data structures etc..
7070
*/
71-
void exit_thread(void)
71+
void exit_thread(struct task_struct *tsk)
7272
{
73-
exit_thread_runtime_instr();
73+
if (tsk == current)
74+
exit_thread_runtime_instr();
7475
}
7576

7677
void flush_thread(void)

arch/sh/kernel/process_64.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ void show_regs(struct pt_regs *regs)
288288
/*
289289
* Free current thread data structures etc..
290290
*/
291-
void exit_thread(void)
291+
void exit_thread(struct task_struct *tsk)
292292
{
293293
/*
294294
* See arch/sparc/kernel/process.c for the precedent for doing
@@ -307,9 +307,8 @@ void exit_thread(void)
307307
* which it would get safely nulled.
308308
*/
309309
#ifdef CONFIG_SH_FPU
310-
if (last_task_used_math == current) {
310+
if (last_task_used_math == tsk)
311311
last_task_used_math = NULL;
312-
}
313312
#endif
314313
}
315314

arch/sparc/kernel/process_32.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -184,21 +184,21 @@ unsigned long thread_saved_pc(struct task_struct *tsk)
184184
/*
185185
* Free current thread data structures etc..
186186
*/
187-
void exit_thread(void)
187+
void exit_thread(struct task_struct *tsk)
188188
{
189189
#ifndef CONFIG_SMP
190-
if(last_task_used_math == current) {
190+
if (last_task_used_math == tsk) {
191191
#else
192-
if (test_thread_flag(TIF_USEDFPU)) {
192+
if (test_ti_thread_flag(task_thread_info(tsk), TIF_USEDFPU)) {
193193
#endif
194194
/* Keep process from leaving FPU in a bogon state. */
195195
put_psr(get_psr() | PSR_EF);
196-
fpsave(&current->thread.float_regs[0], &current->thread.fsr,
197-
&current->thread.fpqueue[0], &current->thread.fpqdepth);
196+
fpsave(&tsk->thread.float_regs[0], &tsk->thread.fsr,
197+
&tsk->thread.fpqueue[0], &tsk->thread.fpqdepth);
198198
#ifndef CONFIG_SMP
199199
last_task_used_math = NULL;
200200
#else
201-
clear_thread_flag(TIF_USEDFPU);
201+
clear_ti_thread_flag(task_thread_info(tsk), TIF_USEDFPU);
202202
#endif
203203
}
204204
}

arch/sparc/kernel/process_64.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,9 +417,9 @@ unsigned long thread_saved_pc(struct task_struct *tsk)
417417
}
418418

419419
/* Free current thread data structures etc.. */
420-
void exit_thread(void)
420+
void exit_thread(struct task_struct *tsk)
421421
{
422-
struct thread_info *t = current_thread_info();
422+
struct thread_info *t = task_thread_info(tsk);
423423

424424
if (t->utraps) {
425425
if (t->utraps[0] < 2)

arch/tile/kernel/process.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ void flush_thread(void)
541541
/*
542542
* Free current thread data structures etc..
543543
*/
544-
void exit_thread(void)
544+
void exit_thread(struct task_struct *tsk)
545545
{
546546
#ifdef CONFIG_HARDWALL
547547
/*
@@ -550,7 +550,7 @@ void exit_thread(void)
550550
* the last reference to a hardwall fd, it would already have
551551
* been released and deactivated at this point.)
552552
*/
553-
hardwall_deactivate_all(current);
553+
hardwall_deactivate_all(tsk);
554554
#endif
555555
}
556556

arch/x86/kernel/process.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,9 @@ int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src)
9797
/*
9898
* Free current thread data structures etc..
9999
*/
100-
void exit_thread(void)
100+
void exit_thread(struct task_struct *tsk)
101101
{
102-
struct task_struct *me = current;
103-
struct thread_struct *t = &me->thread;
102+
struct thread_struct *t = &tsk->thread;
104103
unsigned long *bp = t->io_bitmap_ptr;
105104
struct fpu *fpu = &t->fpu;
106105

arch/xtensa/kernel/process.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,10 @@ void arch_cpu_idle(void)
115115
/*
116116
* This is called when the thread calls exit().
117117
*/
118-
void exit_thread(void)
118+
void exit_thread(struct task_struct *tsk)
119119
{
120120
#if XTENSA_HAVE_COPROCESSORS
121-
coprocessor_release_all(current_thread_info());
121+
coprocessor_release_all(task_thread_info(tsk));
122122
#endif
123123
}
124124

include/linux/sched.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2771,9 +2771,9 @@ static inline int copy_thread_tls(
27712771
extern void flush_thread(void);
27722772

27732773
#ifdef CONFIG_HAVE_EXIT_THREAD
2774-
extern void exit_thread(void);
2774+
extern void exit_thread(struct task_struct *tsk);
27752775
#else
2776-
static inline void exit_thread(void)
2776+
static inline void exit_thread(struct task_struct *tsk)
27772777
{
27782778
}
27792779
#endif

kernel/exit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ void do_exit(long code)
746746
disassociate_ctty(1);
747747
exit_task_namespaces(tsk);
748748
exit_task_work(tsk);
749-
exit_thread();
749+
exit_thread(tsk);
750750

751751
/*
752752
* Flush inherited counters to the parent - before the parent

0 commit comments

Comments
 (0)