Skip to content

Commit

Permalink
Merge pull request torvalds#274 from liuyuan10/fix
Browse files Browse the repository at this point in the history
lkl: Fix race condition on sched_jb
  • Loading branch information
tavip authored Nov 22, 2016
2 parents ac79c65 + 7a62de5 commit 861cf05
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
5 changes: 0 additions & 5 deletions arch/lkl/include/asm/sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ static inline void thread_sched_jb(void)
}
}

static inline void thread_set_sched_exit(void)
{
set_ti_thread_flag(current_thread_info(), TIF_SCHED_EXIT);
}

void switch_to_host_task(struct task_struct *);

#endif /* _ASM_LKL_SCHED_H */
5 changes: 2 additions & 3 deletions arch/lkl/include/asm/thread_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,8 @@ void threads_cnt_dec(void);
#define TIF_MEMDIE 5
#define TIF_NOHZ 6
#define TIF_SCHED_JB 7
#define TIF_SCHED_EXIT 8
#define TIF_HOST_THREAD 9
#define TIF_IDLE 10
#define TIF_HOST_THREAD 8
#define TIF_IDLE 9

#define __HAVE_THREAD_FUNCTIONS

Expand Down
9 changes: 7 additions & 2 deletions arch/lkl/kernel/syscalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,23 @@ static int new_host_task(struct task_struct **task)

return 0;
}
static void exit_task(void)
{
do_exit(0);
}

static void del_host_task(void *arg)
{
struct task_struct *task = (struct task_struct *)arg;
struct thread_info *ti = task_thread_info(task);

if (lkl_cpu_get() < 0)
return;

switch_to_host_task(task);
host_task_id--;
thread_set_sched_exit();
do_exit(0);
set_ti_thread_flag(ti, TIF_SCHED_JB);
lkl_ops->jmp_buf_set(&ti->sched_jb, exit_task);
}

static struct lkl_tls_key *task_key;
Expand Down
6 changes: 3 additions & 3 deletions arch/lkl/kernel/threads.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ struct task_struct *__switch_to(struct task_struct *prev,
unsigned long _prev_flags = _prev->flags;
bool wakeup_idle = test_bit(TIF_IDLE, &_next->flags) &&
lkl_cpu_idle_pending();
struct lkl_jmp_buf _prev_jb;

_current_thread_info = task_thread_info(next);
_next->prev_sched = prev;
Expand All @@ -103,6 +104,7 @@ struct task_struct *__switch_to(struct task_struct *prev,
if (test_bit(TIF_SCHED_JB, &_prev_flags)) {
/* Atomic. Must be done before wakeup next */
clear_ti_thread_flag(_prev, TIF_SCHED_JB);
_prev_jb = _prev->sched_jb;
}
if (wakeup_idle)
schedule_tail(abs_prev);
Expand All @@ -115,9 +117,7 @@ struct task_struct *__switch_to(struct task_struct *prev,
lkl_ops->sem_up(_next->sched_sem);

if (test_bit(TIF_SCHED_JB, &_prev_flags)) {
lkl_ops->jmp_buf_longjmp(&_prev->sched_jb, 1);
} else if (test_bit(TIF_SCHED_EXIT, &_prev_flags)) {
lkl_ops->thread_exit();
lkl_ops->jmp_buf_longjmp(&_prev_jb, 1);
} else {
lkl_ops->sem_down(_prev->sched_sem);
}
Expand Down

0 comments on commit 861cf05

Please sign in to comment.