Skip to content

Commit

Permalink
Merge pull request torvalds#262 from liuyuan10/tls
Browse files Browse the repository at this point in the history
lkl: Fix lkl_sys_halt and memory leak of TIF_HOST_THREAD
  • Loading branch information
tavip authored Nov 12, 2016
2 parents 254389f + c167ea8 commit c011d35
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 10 deletions.
1 change: 1 addition & 0 deletions arch/lkl/include/asm/thread_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ void free_thread_stack(unsigned long *);

void threads_init(void);
void threads_cleanup(void);
void threads_cnt_dec(void);

#define TIF_SYSCALL_TRACE 0
#define TIF_NOTIFY_RESUME 1
Expand Down
5 changes: 4 additions & 1 deletion arch/lkl/kernel/setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ int __init lkl_start_kernel(struct lkl_host_operations *ops,
}

lkl_ops->sem_down(init_sem);
lkl_ops->sem_free(init_sem);
current_thread_info()->tid = lkl_ops->thread_self();
lkl_cpu_change_owner(current_thread_info()->tid);

Expand Down Expand Up @@ -112,7 +113,8 @@ void machine_restart(char *unused)
long lkl_sys_halt(void)
{
long err;
long params[6] = { 0, };
long params[6] = {LINUX_REBOOT_MAGIC1,
LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_RESTART, };

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

syscalls_init();
threads_cnt_dec();

lkl_ops->sem_up(init_sem);
lkl_ops->thread_exit();
Expand Down
7 changes: 7 additions & 0 deletions arch/lkl/kernel/syscalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,13 @@ long lkl_syscall(long no, long *params)

ret = run_syscall(no, params);

if (no == __NR_reboot) {
set_current_state(TASK_UNINTERRUPTIBLE);
if (!thread_set_sched_jmp())
schedule();
return ret;
}

out:
lkl_cpu_put();

Expand Down
21 changes: 13 additions & 8 deletions arch/lkl/kernel/threads.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,18 +225,23 @@ void threads_init(void)
ti->tid = lkl_ops->thread_self();
}

void threads_cnt_dec(void)
{
__sync_fetch_and_sub(&threads_counter, 1);
}

void threads_cleanup(void)
{
struct task_struct *p;
struct task_struct *p, *t;

for_each_process(p) {
struct thread_info *ti = task_thread_info(p);
for_each_process_thread(p, t) {
struct thread_info *ti = task_thread_info(t);

if (p->pid != 1)
WARN(!(p->flags & PF_KTHREAD),
"non kernel thread task %p\n", p->comm);
WARN(p->state == TASK_RUNNING,
"thread %s still running while halting\n", p->comm);
if (t->pid != 1 && !test_ti_thread_flag(ti, TIF_HOST_THREAD))
WARN(!(t->flags & PF_KTHREAD),
"non kernel thread task %s\n", t->comm);
WARN(t->state == TASK_RUNNING,
"thread %s still running while halting\n", t->comm);

kill_thread(ti);
}
Expand Down
5 changes: 4 additions & 1 deletion tools/lkl/lib/hijack/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@ hijack_fini(void)
{
int i;
char *dump = getenv("LKL_HIJACK_DUMP");
int err;

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

lkl_sys_halt();
err = lkl_sys_halt();
if (err)
fprintf(stderr, "lkl_sys_halt: %s\n", lkl_strerror(err));
}

0 comments on commit c011d35

Please sign in to comment.