diff options
Diffstat (limited to 'drivers/android/binder.c')
| -rw-r--r-- | drivers/android/binder.c | 58 | 
1 files changed, 46 insertions, 12 deletions
| diff --git a/drivers/android/binder.c b/drivers/android/binder.c index d9030cb6b1e4..9edacc8b9768 100644 --- a/drivers/android/binder.c +++ b/drivers/android/binder.c @@ -1852,6 +1852,7 @@ static void binder_deferred_fd_close(int fd)  }  static void binder_transaction_buffer_release(struct binder_proc *proc, +					      struct binder_thread *thread,  					      struct binder_buffer *buffer,  					      binder_size_t failed_at,  					      bool is_failure) @@ -2011,8 +2012,16 @@ static void binder_transaction_buffer_release(struct binder_proc *proc,  						&proc->alloc, &fd, buffer,  						offset, sizeof(fd));  				WARN_ON(err); -				if (!err) +				if (!err) {  					binder_deferred_fd_close(fd); +					/* +					 * Need to make sure the thread goes +					 * back to userspace to complete the +					 * deferred close +					 */ +					if (thread) +						thread->looper_need_return = true; +				}  			}  		} break;  		default: @@ -3038,9 +3047,8 @@ static void binder_transaction(struct binder_proc *proc,  	if (reply) {  		binder_enqueue_thread_work(thread, tcomplete);  		binder_inner_proc_lock(target_proc); -		if (target_thread->is_dead || target_proc->is_frozen) { -			return_error = target_thread->is_dead ? -				BR_DEAD_REPLY : BR_FROZEN_REPLY; +		if (target_thread->is_dead) { +			return_error = BR_DEAD_REPLY;  			binder_inner_proc_unlock(target_proc);  			goto err_dead_proc_or_thread;  		} @@ -3105,7 +3113,7 @@ err_bad_parent:  err_copy_data_failed:  	binder_free_txn_fixups(t);  	trace_binder_transaction_failed_buffer_release(t->buffer); -	binder_transaction_buffer_release(target_proc, t->buffer, +	binder_transaction_buffer_release(target_proc, NULL, t->buffer,  					  buffer_offset, true);  	if (target_node)  		binder_dec_node_tmpref(target_node); @@ -3184,7 +3192,9 @@ err_invalid_target_handle:   * Cleanup buffer and free it.   */  static void -binder_free_buf(struct binder_proc *proc, struct binder_buffer *buffer) +binder_free_buf(struct binder_proc *proc, +		struct binder_thread *thread, +		struct binder_buffer *buffer)  {  	binder_inner_proc_lock(proc);  	if (buffer->transaction) { @@ -3212,7 +3222,7 @@ binder_free_buf(struct binder_proc *proc, struct binder_buffer *buffer)  		binder_node_inner_unlock(buf_node);  	}  	trace_binder_transaction_buffer_release(buffer); -	binder_transaction_buffer_release(proc, buffer, 0, false); +	binder_transaction_buffer_release(proc, thread, buffer, 0, false);  	binder_alloc_free_buf(&proc->alloc, buffer);  } @@ -3414,7 +3424,7 @@ static int binder_thread_write(struct binder_proc *proc,  				     proc->pid, thread->pid, (u64)data_ptr,  				     buffer->debug_id,  				     buffer->transaction ? "active" : "finished"); -			binder_free_buf(proc, buffer); +			binder_free_buf(proc, thread, buffer);  			break;  		} @@ -4107,7 +4117,7 @@ retry:  			buffer->transaction = NULL;  			binder_cleanup_transaction(t, "fd fixups failed",  						   BR_FAILED_REPLY); -			binder_free_buf(proc, buffer); +			binder_free_buf(proc, thread, buffer);  			binder_debug(BINDER_DEBUG_FAILED_TRANSACTION,  				     "%d:%d %stransaction %d fd fixups failed %d/%d, line %d\n",  				     proc->pid, thread->pid, @@ -4648,6 +4658,22 @@ static int binder_ioctl_get_node_debug_info(struct binder_proc *proc,  	return 0;  } +static bool binder_txns_pending_ilocked(struct binder_proc *proc) +{ +	struct rb_node *n; +	struct binder_thread *thread; + +	if (proc->outstanding_txns > 0) +		return true; + +	for (n = rb_first(&proc->threads); n; n = rb_next(n)) { +		thread = rb_entry(n, struct binder_thread, rb_node); +		if (thread->transaction_stack) +			return true; +	} +	return false; +} +  static int binder_ioctl_freeze(struct binder_freeze_info *info,  			       struct binder_proc *target_proc)  { @@ -4679,8 +4705,13 @@ static int binder_ioctl_freeze(struct binder_freeze_info *info,  			(!target_proc->outstanding_txns),  			msecs_to_jiffies(info->timeout_ms)); -	if (!ret && target_proc->outstanding_txns) -		ret = -EAGAIN; +	/* Check pending transactions that wait for reply */ +	if (ret >= 0) { +		binder_inner_proc_lock(target_proc); +		if (binder_txns_pending_ilocked(target_proc)) +			ret = -EAGAIN; +		binder_inner_proc_unlock(target_proc); +	}  	if (ret < 0) {  		binder_inner_proc_lock(target_proc); @@ -4696,6 +4727,7 @@ static int binder_ioctl_get_freezer_info(  {  	struct binder_proc *target_proc;  	bool found = false; +	__u32 txns_pending;  	info->sync_recv = 0;  	info->async_recv = 0; @@ -4705,7 +4737,9 @@ static int binder_ioctl_get_freezer_info(  		if (target_proc->pid == info->pid) {  			found = true;  			binder_inner_proc_lock(target_proc); -			info->sync_recv |= target_proc->sync_recv; +			txns_pending = binder_txns_pending_ilocked(target_proc); +			info->sync_recv |= target_proc->sync_recv | +					(txns_pending << 1);  			info->async_recv |= target_proc->async_recv;  			binder_inner_proc_unlock(target_proc);  		} |