Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lkl: Fix lkl_sys_halt and memory leak of TIF_HOST_THREAD #262

Merged
merged 2 commits into from
Nov 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a big deal, but we probably want to use LINUX_REBOOT_CMD_HALT instead, just to match the API name.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the kernel/reboot.c, LINUX_REBOOT_CMD_HALT will call do_exit which is not what we want.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point.


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));
}