mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-06-29 10:01:25 +00:00
binder: don't modify thread->looper from other threads
The looper member of struct binder_thread is a bitmask of control bits. All of the existing bits are modified by the affected thread except for BINDER_LOOPER_STATE_NEED_RETURN which can be modified in binder_deferred_flush() by another thread. To avoid adding a spinlock around all read-mod-writes to modify a bit, the BINDER_LOOPER_STATE_NEED_RETURN flag is replaced by a separate field in struct binder_thread. Signed-off-by: Todd Kjos <tkjos@google.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
ccae6f6760
commit
08dabceefe
1 changed files with 11 additions and 11 deletions
|
@ -334,14 +334,14 @@ enum {
|
||||||
BINDER_LOOPER_STATE_EXITED = 0x04,
|
BINDER_LOOPER_STATE_EXITED = 0x04,
|
||||||
BINDER_LOOPER_STATE_INVALID = 0x08,
|
BINDER_LOOPER_STATE_INVALID = 0x08,
|
||||||
BINDER_LOOPER_STATE_WAITING = 0x10,
|
BINDER_LOOPER_STATE_WAITING = 0x10,
|
||||||
BINDER_LOOPER_STATE_NEED_RETURN = 0x20
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct binder_thread {
|
struct binder_thread {
|
||||||
struct binder_proc *proc;
|
struct binder_proc *proc;
|
||||||
struct rb_node rb_node;
|
struct rb_node rb_node;
|
||||||
int pid;
|
int pid;
|
||||||
int looper;
|
int looper; /* only modified by this thread */
|
||||||
|
bool looper_need_return; /* can be written by other thread */
|
||||||
struct binder_transaction *transaction_stack;
|
struct binder_transaction *transaction_stack;
|
||||||
struct list_head todo;
|
struct list_head todo;
|
||||||
uint32_t return_error; /* Write failed, return error code in read buf */
|
uint32_t return_error; /* Write failed, return error code in read buf */
|
||||||
|
@ -2276,14 +2276,13 @@ static void binder_stat_br(struct binder_proc *proc,
|
||||||
static int binder_has_proc_work(struct binder_proc *proc,
|
static int binder_has_proc_work(struct binder_proc *proc,
|
||||||
struct binder_thread *thread)
|
struct binder_thread *thread)
|
||||||
{
|
{
|
||||||
return !list_empty(&proc->todo) ||
|
return !list_empty(&proc->todo) || thread->looper_need_return;
|
||||||
(thread->looper & BINDER_LOOPER_STATE_NEED_RETURN);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int binder_has_thread_work(struct binder_thread *thread)
|
static int binder_has_thread_work(struct binder_thread *thread)
|
||||||
{
|
{
|
||||||
return !list_empty(&thread->todo) || thread->return_error != BR_OK ||
|
return !list_empty(&thread->todo) || thread->return_error != BR_OK ||
|
||||||
(thread->looper & BINDER_LOOPER_STATE_NEED_RETURN);
|
thread->looper_need_return;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int binder_put_node_cmd(struct binder_proc *proc,
|
static int binder_put_node_cmd(struct binder_proc *proc,
|
||||||
|
@ -2412,8 +2411,7 @@ retry:
|
||||||
entry);
|
entry);
|
||||||
} else {
|
} else {
|
||||||
/* no data added */
|
/* no data added */
|
||||||
if (ptr - buffer == 4 &&
|
if (ptr - buffer == 4 && !thread->looper_need_return)
|
||||||
!(thread->looper & BINDER_LOOPER_STATE_NEED_RETURN))
|
|
||||||
goto retry;
|
goto retry;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -2727,7 +2725,7 @@ static struct binder_thread *binder_get_thread(struct binder_proc *proc)
|
||||||
INIT_LIST_HEAD(&thread->todo);
|
INIT_LIST_HEAD(&thread->todo);
|
||||||
rb_link_node(&thread->rb_node, parent, p);
|
rb_link_node(&thread->rb_node, parent, p);
|
||||||
rb_insert_color(&thread->rb_node, &proc->threads);
|
rb_insert_color(&thread->rb_node, &proc->threads);
|
||||||
thread->looper |= BINDER_LOOPER_STATE_NEED_RETURN;
|
thread->looper_need_return = true;
|
||||||
thread->return_error = BR_OK;
|
thread->return_error = BR_OK;
|
||||||
thread->return_error2 = BR_OK;
|
thread->return_error2 = BR_OK;
|
||||||
}
|
}
|
||||||
|
@ -2983,7 +2981,7 @@ static long binder_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
|
||||||
ret = 0;
|
ret = 0;
|
||||||
err:
|
err:
|
||||||
if (thread)
|
if (thread)
|
||||||
thread->looper &= ~BINDER_LOOPER_STATE_NEED_RETURN;
|
thread->looper_need_return = false;
|
||||||
binder_unlock(__func__);
|
binder_unlock(__func__);
|
||||||
wait_event_interruptible(binder_user_error_wait, binder_stop_on_user_error < 2);
|
wait_event_interruptible(binder_user_error_wait, binder_stop_on_user_error < 2);
|
||||||
if (ret && ret != -ERESTARTSYS)
|
if (ret && ret != -ERESTARTSYS)
|
||||||
|
@ -3138,7 +3136,7 @@ static void binder_deferred_flush(struct binder_proc *proc)
|
||||||
for (n = rb_first(&proc->threads); n != NULL; n = rb_next(n)) {
|
for (n = rb_first(&proc->threads); n != NULL; n = rb_next(n)) {
|
||||||
struct binder_thread *thread = rb_entry(n, struct binder_thread, rb_node);
|
struct binder_thread *thread = rb_entry(n, struct binder_thread, rb_node);
|
||||||
|
|
||||||
thread->looper |= BINDER_LOOPER_STATE_NEED_RETURN;
|
thread->looper_need_return = true;
|
||||||
if (thread->looper & BINDER_LOOPER_STATE_WAITING) {
|
if (thread->looper & BINDER_LOOPER_STATE_WAITING) {
|
||||||
wake_up_interruptible(&thread->wait);
|
wake_up_interruptible(&thread->wait);
|
||||||
wake_count++;
|
wake_count++;
|
||||||
|
@ -3399,7 +3397,9 @@ static void print_binder_thread(struct seq_file *m,
|
||||||
size_t start_pos = m->count;
|
size_t start_pos = m->count;
|
||||||
size_t header_pos;
|
size_t header_pos;
|
||||||
|
|
||||||
seq_printf(m, " thread %d: l %02x\n", thread->pid, thread->looper);
|
seq_printf(m, " thread %d: l %02x need_return %d\n",
|
||||||
|
thread->pid, thread->looper,
|
||||||
|
thread->looper_need_return);
|
||||||
header_pos = m->count;
|
header_pos = m->count;
|
||||||
t = thread->transaction_stack;
|
t = thread->transaction_stack;
|
||||||
while (t) {
|
while (t) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue