Skip to content

Commit c011d35

Browse files
authored
Merge pull request torvalds#262 from liuyuan10/tls
lkl: Fix lkl_sys_halt and memory leak of TIF_HOST_THREAD
2 parents 254389f + c167ea8 commit c011d35

File tree

5 files changed

+29
-10
lines changed

5 files changed

+29
-10
lines changed

arch/lkl/include/asm/thread_info.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ void free_thread_stack(unsigned long *);
4949

5050
void threads_init(void);
5151
void threads_cleanup(void);
52+
void threads_cnt_dec(void);
5253

5354
#define TIF_SYSCALL_TRACE 0
5455
#define TIF_NOTIFY_RESUME 1

arch/lkl/kernel/setup.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ int __init lkl_start_kernel(struct lkl_host_operations *ops,
7575
}
7676

7777
lkl_ops->sem_down(init_sem);
78+
lkl_ops->sem_free(init_sem);
7879
current_thread_info()->tid = lkl_ops->thread_self();
7980
lkl_cpu_change_owner(current_thread_info()->tid);
8081

@@ -112,7 +113,8 @@ void machine_restart(char *unused)
112113
long lkl_sys_halt(void)
113114
{
114115
long err;
115-
long params[6] = { 0, };
116+
long params[6] = {LINUX_REBOOT_MAGIC1,
117+
LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_RESTART, };
116118

117119
err = lkl_syscall(__NR_reboot, params);
118120
if (err < 0)
@@ -158,6 +160,7 @@ static int lkl_run_init(struct linux_binprm *bprm)
158160
init_pid_ns.child_reaper = 0;
159161

160162
syscalls_init();
163+
threads_cnt_dec();
161164

162165
lkl_ops->sem_up(init_sem);
163166
lkl_ops->thread_exit();

arch/lkl/kernel/syscalls.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,13 @@ long lkl_syscall(long no, long *params)
113113

114114
ret = run_syscall(no, params);
115115

116+
if (no == __NR_reboot) {
117+
set_current_state(TASK_UNINTERRUPTIBLE);
118+
if (!thread_set_sched_jmp())
119+
schedule();
120+
return ret;
121+
}
122+
116123
out:
117124
lkl_cpu_put();
118125

arch/lkl/kernel/threads.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -225,18 +225,23 @@ void threads_init(void)
225225
ti->tid = lkl_ops->thread_self();
226226
}
227227

228+
void threads_cnt_dec(void)
229+
{
230+
__sync_fetch_and_sub(&threads_counter, 1);
231+
}
232+
228233
void threads_cleanup(void)
229234
{
230-
struct task_struct *p;
235+
struct task_struct *p, *t;
231236

232-
for_each_process(p) {
233-
struct thread_info *ti = task_thread_info(p);
237+
for_each_process_thread(p, t) {
238+
struct thread_info *ti = task_thread_info(t);
234239

235-
if (p->pid != 1)
236-
WARN(!(p->flags & PF_KTHREAD),
237-
"non kernel thread task %p\n", p->comm);
238-
WARN(p->state == TASK_RUNNING,
239-
"thread %s still running while halting\n", p->comm);
240+
if (t->pid != 1 && !test_ti_thread_flag(ti, TIF_HOST_THREAD))
241+
WARN(!(t->flags & PF_KTHREAD),
242+
"non kernel thread task %s\n", t->comm);
243+
WARN(t->state == TASK_RUNNING,
244+
"thread %s still running while halting\n", t->comm);
240245

241246
kill_thread(ti);
242247
}

tools/lkl/lib/hijack/init.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,7 @@ hijack_fini(void)
433433
{
434434
int i;
435435
char *dump = getenv("LKL_HIJACK_DUMP");
436+
int err;
436437

437438
/* The following pauses the kernel before exiting allowing one
438439
* to debug or collect stattistics/diagnosis info from it.
@@ -453,5 +454,7 @@ hijack_fini(void)
453454
if (nd)
454455
lkl_netdev_free(nd);
455456

456-
lkl_sys_halt();
457+
err = lkl_sys_halt();
458+
if (err)
459+
fprintf(stderr, "lkl_sys_halt: %s\n", lkl_strerror(err));
457460
}

0 commit comments

Comments
 (0)