Commit 0567461a authored by Li Li's avatar Li Li Committed by Greg Kroah-Hartman

binder: return pending info for frozen async txns

An async transaction to a frozen process will still be successfully
put in the queue. But this pending async transaction won't be processed
until the target process is unfrozen at an unspecified time in the
future. Pass this important information back to the user space caller
by returning BR_TRANSACTION_PENDING_FROZEN.
Signed-off-by: default avatarLi Li <dualli@google.com>
Acked-by: default avatarCarlos Llamas <cmllamas@google.com>
Link: https://lore.kernel.org/r/20221123201654.589322-2-dualli@chromium.orgSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 7feb35bc
...@@ -2728,7 +2728,10 @@ binder_find_outdated_transaction_ilocked(struct binder_transaction *t, ...@@ -2728,7 +2728,10 @@ binder_find_outdated_transaction_ilocked(struct binder_transaction *t,
* *
* Return: 0 if the transaction was successfully queued * Return: 0 if the transaction was successfully queued
* BR_DEAD_REPLY if the target process or thread is dead * BR_DEAD_REPLY if the target process or thread is dead
* BR_FROZEN_REPLY if the target process or thread is frozen * BR_FROZEN_REPLY if the target process or thread is frozen and
* the sync transaction was rejected
* BR_TRANSACTION_PENDING_FROZEN if the target process is frozen
* and the async transaction was successfully queued
*/ */
static int binder_proc_transaction(struct binder_transaction *t, static int binder_proc_transaction(struct binder_transaction *t,
struct binder_proc *proc, struct binder_proc *proc,
...@@ -2738,6 +2741,7 @@ static int binder_proc_transaction(struct binder_transaction *t, ...@@ -2738,6 +2741,7 @@ static int binder_proc_transaction(struct binder_transaction *t,
bool oneway = !!(t->flags & TF_ONE_WAY); bool oneway = !!(t->flags & TF_ONE_WAY);
bool pending_async = false; bool pending_async = false;
struct binder_transaction *t_outdated = NULL; struct binder_transaction *t_outdated = NULL;
bool frozen = false;
BUG_ON(!node); BUG_ON(!node);
binder_node_lock(node); binder_node_lock(node);
...@@ -2751,15 +2755,16 @@ static int binder_proc_transaction(struct binder_transaction *t, ...@@ -2751,15 +2755,16 @@ static int binder_proc_transaction(struct binder_transaction *t,
binder_inner_proc_lock(proc); binder_inner_proc_lock(proc);
if (proc->is_frozen) { if (proc->is_frozen) {
frozen = true;
proc->sync_recv |= !oneway; proc->sync_recv |= !oneway;
proc->async_recv |= oneway; proc->async_recv |= oneway;
} }
if ((proc->is_frozen && !oneway) || proc->is_dead || if ((frozen && !oneway) || proc->is_dead ||
(thread && thread->is_dead)) { (thread && thread->is_dead)) {
binder_inner_proc_unlock(proc); binder_inner_proc_unlock(proc);
binder_node_unlock(node); binder_node_unlock(node);
return proc->is_frozen ? BR_FROZEN_REPLY : BR_DEAD_REPLY; return frozen ? BR_FROZEN_REPLY : BR_DEAD_REPLY;
} }
if (!thread && !pending_async) if (!thread && !pending_async)
...@@ -2770,7 +2775,7 @@ static int binder_proc_transaction(struct binder_transaction *t, ...@@ -2770,7 +2775,7 @@ static int binder_proc_transaction(struct binder_transaction *t,
} else if (!pending_async) { } else if (!pending_async) {
binder_enqueue_work_ilocked(&t->work, &proc->todo); binder_enqueue_work_ilocked(&t->work, &proc->todo);
} else { } else {
if ((t->flags & TF_UPDATE_TXN) && proc->is_frozen) { if ((t->flags & TF_UPDATE_TXN) && frozen) {
t_outdated = binder_find_outdated_transaction_ilocked(t, t_outdated = binder_find_outdated_transaction_ilocked(t,
&node->async_todo); &node->async_todo);
if (t_outdated) { if (t_outdated) {
...@@ -2807,6 +2812,9 @@ static int binder_proc_transaction(struct binder_transaction *t, ...@@ -2807,6 +2812,9 @@ static int binder_proc_transaction(struct binder_transaction *t,
binder_stats_deleted(BINDER_STAT_TRANSACTION); binder_stats_deleted(BINDER_STAT_TRANSACTION);
} }
if (oneway && frozen)
return BR_TRANSACTION_PENDING_FROZEN;
return 0; return 0;
} }
...@@ -3607,9 +3615,17 @@ static void binder_transaction(struct binder_proc *proc, ...@@ -3607,9 +3615,17 @@ static void binder_transaction(struct binder_proc *proc,
} else { } else {
BUG_ON(target_node == NULL); BUG_ON(target_node == NULL);
BUG_ON(t->buffer->async_transaction != 1); BUG_ON(t->buffer->async_transaction != 1);
binder_enqueue_thread_work(thread, tcomplete);
return_error = binder_proc_transaction(t, target_proc, NULL); return_error = binder_proc_transaction(t, target_proc, NULL);
if (return_error) /*
* Let the caller know when async transaction reaches a frozen
* process and is put in a pending queue, waiting for the target
* process to be unfrozen.
*/
if (return_error == BR_TRANSACTION_PENDING_FROZEN)
tcomplete->type = BINDER_WORK_TRANSACTION_PENDING;
binder_enqueue_thread_work(thread, tcomplete);
if (return_error &&
return_error != BR_TRANSACTION_PENDING_FROZEN)
goto err_dead_proc_or_thread; goto err_dead_proc_or_thread;
} }
if (target_thread) if (target_thread)
...@@ -4440,10 +4456,13 @@ static int binder_thread_read(struct binder_proc *proc, ...@@ -4440,10 +4456,13 @@ static int binder_thread_read(struct binder_proc *proc,
binder_stat_br(proc, thread, cmd); binder_stat_br(proc, thread, cmd);
} break; } break;
case BINDER_WORK_TRANSACTION_COMPLETE: case BINDER_WORK_TRANSACTION_COMPLETE:
case BINDER_WORK_TRANSACTION_PENDING:
case BINDER_WORK_TRANSACTION_ONEWAY_SPAM_SUSPECT: { case BINDER_WORK_TRANSACTION_ONEWAY_SPAM_SUSPECT: {
if (proc->oneway_spam_detection_enabled && if (proc->oneway_spam_detection_enabled &&
w->type == BINDER_WORK_TRANSACTION_ONEWAY_SPAM_SUSPECT) w->type == BINDER_WORK_TRANSACTION_ONEWAY_SPAM_SUSPECT)
cmd = BR_ONEWAY_SPAM_SUSPECT; cmd = BR_ONEWAY_SPAM_SUSPECT;
else if (w->type == BINDER_WORK_TRANSACTION_PENDING)
cmd = BR_TRANSACTION_PENDING_FROZEN;
else else
cmd = BR_TRANSACTION_COMPLETE; cmd = BR_TRANSACTION_COMPLETE;
binder_inner_proc_unlock(proc); binder_inner_proc_unlock(proc);
...@@ -6159,6 +6178,7 @@ static const char * const binder_return_strings[] = { ...@@ -6159,6 +6178,7 @@ static const char * const binder_return_strings[] = {
"BR_FAILED_REPLY", "BR_FAILED_REPLY",
"BR_FROZEN_REPLY", "BR_FROZEN_REPLY",
"BR_ONEWAY_SPAM_SUSPECT", "BR_ONEWAY_SPAM_SUSPECT",
"BR_TRANSACTION_PENDING_FROZEN"
}; };
static const char * const binder_command_strings[] = { static const char * const binder_command_strings[] = {
......
...@@ -133,7 +133,7 @@ enum binder_stat_types { ...@@ -133,7 +133,7 @@ enum binder_stat_types {
}; };
struct binder_stats { struct binder_stats {
atomic_t br[_IOC_NR(BR_ONEWAY_SPAM_SUSPECT) + 1]; atomic_t br[_IOC_NR(BR_TRANSACTION_PENDING_FROZEN) + 1];
atomic_t bc[_IOC_NR(BC_REPLY_SG) + 1]; atomic_t bc[_IOC_NR(BC_REPLY_SG) + 1];
atomic_t obj_created[BINDER_STAT_COUNT]; atomic_t obj_created[BINDER_STAT_COUNT];
atomic_t obj_deleted[BINDER_STAT_COUNT]; atomic_t obj_deleted[BINDER_STAT_COUNT];
...@@ -152,6 +152,7 @@ struct binder_work { ...@@ -152,6 +152,7 @@ struct binder_work {
enum binder_work_type { enum binder_work_type {
BINDER_WORK_TRANSACTION = 1, BINDER_WORK_TRANSACTION = 1,
BINDER_WORK_TRANSACTION_COMPLETE, BINDER_WORK_TRANSACTION_COMPLETE,
BINDER_WORK_TRANSACTION_PENDING,
BINDER_WORK_TRANSACTION_ONEWAY_SPAM_SUSPECT, BINDER_WORK_TRANSACTION_ONEWAY_SPAM_SUSPECT,
BINDER_WORK_RETURN_ERROR, BINDER_WORK_RETURN_ERROR,
BINDER_WORK_NODE, BINDER_WORK_NODE,
......
...@@ -450,7 +450,7 @@ enum binder_driver_return_protocol { ...@@ -450,7 +450,7 @@ enum binder_driver_return_protocol {
BR_FROZEN_REPLY = _IO('r', 18), BR_FROZEN_REPLY = _IO('r', 18),
/* /*
* The target of the last transaction (either a bcTRANSACTION or * The target of the last sync transaction (either a bcTRANSACTION or
* a bcATTEMPT_ACQUIRE) is frozen. No parameters. * a bcATTEMPT_ACQUIRE) is frozen. No parameters.
*/ */
...@@ -460,6 +460,11 @@ enum binder_driver_return_protocol { ...@@ -460,6 +460,11 @@ enum binder_driver_return_protocol {
* asynchronous transaction makes the allocated async buffer size exceed * asynchronous transaction makes the allocated async buffer size exceed
* detection threshold. No parameters. * detection threshold. No parameters.
*/ */
BR_TRANSACTION_PENDING_FROZEN = _IO('r', 20),
/*
* The target of the last async transaction is frozen. No parameters.
*/
}; };
enum binder_driver_command_protocol { enum binder_driver_command_protocol {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment