2011-11-30 20:18:14 +09:00
|
|
|
/* binder.c
|
|
|
|
*
|
|
|
|
* Android IPC Subsystem
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007-2008 Google, Inc.
|
|
|
|
*
|
|
|
|
* This software is licensed under the terms of the GNU General Public
|
|
|
|
* License version 2, as published by the Free Software Foundation, and
|
|
|
|
* may be copied, distributed, and modified under those terms.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2017-05-29 16:44:24 -07:00
|
|
|
/*
|
|
|
|
* Locking overview
|
|
|
|
*
|
|
|
|
* There are 3 main spinlocks which must be acquired in the
|
|
|
|
* order shown:
|
|
|
|
*
|
|
|
|
* 1) proc->outer_lock : protects binder_ref
|
|
|
|
* binder_proc_lock() and binder_proc_unlock() are
|
|
|
|
* used to acq/rel.
|
|
|
|
* 2) node->lock : protects most fields of binder_node.
|
|
|
|
* binder_node_lock() and binder_node_unlock() are
|
|
|
|
* used to acq/rel
|
|
|
|
* 3) proc->inner_lock : protects the thread and node lists
|
2017-06-02 11:15:44 -07:00
|
|
|
* (proc->threads, proc->waiting_threads, proc->nodes)
|
|
|
|
* and all todo lists associated with the binder_proc
|
|
|
|
* (proc->todo, thread->todo, proc->delivered_death and
|
|
|
|
* node->async_todo), as well as thread->transaction_stack
|
2017-05-29 16:44:24 -07:00
|
|
|
* binder_inner_proc_lock() and binder_inner_proc_unlock()
|
|
|
|
* are used to acq/rel
|
|
|
|
*
|
|
|
|
* Any lock under procA must never be nested under any lock at the same
|
|
|
|
* level or below on procB.
|
|
|
|
*
|
|
|
|
* Functions that require a lock held on entry indicate which lock
|
|
|
|
* in the suffix of the function name:
|
|
|
|
*
|
|
|
|
* foo_olocked() : requires node->outer_lock
|
|
|
|
* foo_nlocked() : requires node->lock
|
|
|
|
* foo_ilocked() : requires proc->inner_lock
|
|
|
|
* foo_oilocked(): requires proc->outer_lock and proc->inner_lock
|
|
|
|
* foo_nilocked(): requires node->lock and proc->inner_lock
|
|
|
|
* ...
|
|
|
|
*/
|
|
|
|
|
2012-10-30 22:35:43 +05:30
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
|
2011-11-30 20:18:14 +09:00
|
|
|
#include <asm/cacheflush.h>
|
|
|
|
#include <linux/fdtable.h>
|
|
|
|
#include <linux/file.h>
|
2013-05-06 23:50:15 +00:00
|
|
|
#include <linux/freezer.h>
|
2011-11-30 20:18:14 +09:00
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/list.h>
|
|
|
|
#include <linux/miscdevice.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/mutex.h>
|
|
|
|
#include <linux/nsproxy.h>
|
|
|
|
#include <linux/poll.h>
|
2009-04-28 20:57:50 -07:00
|
|
|
#include <linux/debugfs.h>
|
2011-11-30 20:18:14 +09:00
|
|
|
#include <linux/rbtree.h>
|
|
|
|
#include <linux/sched.h>
|
2009-04-28 20:57:50 -07:00
|
|
|
#include <linux/seq_file.h>
|
2011-11-30 20:18:14 +09:00
|
|
|
#include <linux/uaccess.h>
|
2010-03-02 14:51:53 -08:00
|
|
|
#include <linux/pid_namespace.h>
|
2015-01-21 10:54:10 -05:00
|
|
|
#include <linux/security.h>
|
2017-05-29 16:44:24 -07:00
|
|
|
#include <linux/spinlock.h>
|
2011-11-30 20:18:14 +09:00
|
|
|
|
2014-10-16 15:26:51 +02:00
|
|
|
#ifdef CONFIG_ANDROID_BINDER_IPC_32BIT
|
|
|
|
#define BINDER_IPC_32BIT 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <uapi/linux/android/binder.h>
|
2016-10-10 10:40:53 -07:00
|
|
|
#include "binder_alloc.h"
|
2012-10-16 15:29:53 -07:00
|
|
|
#include "binder_trace.h"
|
2011-11-30 20:18:14 +09:00
|
|
|
|
2016-10-17 12:33:15 -07:00
|
|
|
static HLIST_HEAD(binder_deferred_list);
|
2017-03-24 15:53:53 -07:00
|
|
|
static DEFINE_MUTEX(binder_deferred_lock);
|
|
|
|
|
2016-09-30 16:08:09 +02:00
|
|
|
static HLIST_HEAD(binder_devices);
|
2017-03-24 15:53:53 -07:00
|
|
|
static HLIST_HEAD(binder_procs);
|
2016-10-17 12:33:15 -07:00
|
|
|
static DEFINE_MUTEX(binder_procs_lock);
|
|
|
|
|
2017-03-24 15:53:53 -07:00
|
|
|
static HLIST_HEAD(binder_dead_nodes);
|
2016-10-17 12:33:15 -07:00
|
|
|
static DEFINE_SPINLOCK(binder_dead_nodes_lock);
|
2011-11-30 20:18:14 +09:00
|
|
|
|
2009-04-28 20:57:50 -07:00
|
|
|
static struct dentry *binder_debugfs_dir_entry_root;
|
|
|
|
static struct dentry *binder_debugfs_dir_entry_proc;
|
2017-05-25 10:56:00 -07:00
|
|
|
static atomic_t binder_last_id;
|
2017-03-24 15:53:53 -07:00
|
|
|
static struct workqueue_struct *binder_deferred_workqueue;
|
2011-11-30 20:18:14 +09:00
|
|
|
|
2009-04-28 20:57:50 -07:00
|
|
|
#define BINDER_DEBUG_ENTRY(name) \
|
|
|
|
static int binder_##name##_open(struct inode *inode, struct file *file) \
|
|
|
|
{ \
|
2009-04-28 20:57:50 -07:00
|
|
|
return single_open(file, binder_##name##_show, inode->i_private); \
|
2009-04-28 20:57:50 -07:00
|
|
|
} \
|
|
|
|
\
|
|
|
|
static const struct file_operations binder_##name##_fops = { \
|
|
|
|
.owner = THIS_MODULE, \
|
|
|
|
.open = binder_##name##_open, \
|
|
|
|
.read = seq_read, \
|
|
|
|
.llseek = seq_lseek, \
|
|
|
|
.release = single_release, \
|
|
|
|
}
|
|
|
|
|
|
|
|
static int binder_proc_show(struct seq_file *m, void *unused);
|
|
|
|
BINDER_DEBUG_ENTRY(proc);
|
2011-11-30 20:18:14 +09:00
|
|
|
|
|
|
|
/* This is only defined in include/asm-arm/sizes.h */
|
|
|
|
#ifndef SZ_1K
|
|
|
|
#define SZ_1K 0x400
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef SZ_4M
|
|
|
|
#define SZ_4M 0x400000
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define FORBIDDEN_MMAP_FLAGS (VM_WRITE)
|
|
|
|
|
|
|
|
#define BINDER_SMALL_BUF_SIZE (PAGE_SIZE * 64)
|
|
|
|
|
|
|
|
enum {
|
|
|
|
BINDER_DEBUG_USER_ERROR = 1U << 0,
|
|
|
|
BINDER_DEBUG_FAILED_TRANSACTION = 1U << 1,
|
|
|
|
BINDER_DEBUG_DEAD_TRANSACTION = 1U << 2,
|
|
|
|
BINDER_DEBUG_OPEN_CLOSE = 1U << 3,
|
|
|
|
BINDER_DEBUG_DEAD_BINDER = 1U << 4,
|
|
|
|
BINDER_DEBUG_DEATH_NOTIFICATION = 1U << 5,
|
|
|
|
BINDER_DEBUG_READ_WRITE = 1U << 6,
|
|
|
|
BINDER_DEBUG_USER_REFS = 1U << 7,
|
|
|
|
BINDER_DEBUG_THREADS = 1U << 8,
|
|
|
|
BINDER_DEBUG_TRANSACTION = 1U << 9,
|
|
|
|
BINDER_DEBUG_TRANSACTION_COMPLETE = 1U << 10,
|
|
|
|
BINDER_DEBUG_FREE_BUFFER = 1U << 11,
|
|
|
|
BINDER_DEBUG_INTERNAL_REFS = 1U << 12,
|
2016-10-10 10:40:53 -07:00
|
|
|
BINDER_DEBUG_PRIORITY_CAP = 1U << 13,
|
2017-05-29 16:44:24 -07:00
|
|
|
BINDER_DEBUG_SPINLOCKS = 1U << 14,
|
2011-11-30 20:18:14 +09:00
|
|
|
};
|
|
|
|
static uint32_t binder_debug_mask = BINDER_DEBUG_USER_ERROR |
|
|
|
|
BINDER_DEBUG_FAILED_TRANSACTION | BINDER_DEBUG_DEAD_TRANSACTION;
|
|
|
|
module_param_named(debug_mask, binder_debug_mask, uint, S_IWUSR | S_IRUGO);
|
|
|
|
|
2016-09-30 16:08:09 +02:00
|
|
|
static char *binder_devices_param = CONFIG_ANDROID_BINDER_DEVICES;
|
|
|
|
module_param_named(devices, binder_devices_param, charp, S_IRUGO);
|
|
|
|
|
2011-11-30 20:18:14 +09:00
|
|
|
static DECLARE_WAIT_QUEUE_HEAD(binder_user_error_wait);
|
|
|
|
static int binder_stop_on_user_error;
|
|
|
|
|
|
|
|
static int binder_set_stop_on_user_error(const char *val,
|
|
|
|
struct kernel_param *kp)
|
|
|
|
{
|
|
|
|
int ret;
|
2014-05-01 01:30:23 +09:00
|
|
|
|
2011-11-30 20:18:14 +09:00
|
|
|
ret = param_set_int(val, kp);
|
|
|
|
if (binder_stop_on_user_error < 2)
|
|
|
|
wake_up(&binder_user_error_wait);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
module_param_call(stop_on_user_error, binder_set_stop_on_user_error,
|
|
|
|
param_get_int, &binder_stop_on_user_error, S_IWUSR | S_IRUGO);
|
|
|
|
|
|
|
|
#define binder_debug(mask, x...) \
|
|
|
|
do { \
|
|
|
|
if (binder_debug_mask & mask) \
|
2012-06-26 02:00:30 -04:00
|
|
|
pr_info(x); \
|
2011-11-30 20:18:14 +09:00
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define binder_user_error(x...) \
|
|
|
|
do { \
|
|
|
|
if (binder_debug_mask & BINDER_DEBUG_USER_ERROR) \
|
2012-06-26 02:00:30 -04:00
|
|
|
pr_info(x); \
|
2011-11-30 20:18:14 +09:00
|
|
|
if (binder_stop_on_user_error) \
|
|
|
|
binder_stop_on_user_error = 2; \
|
|
|
|
} while (0)
|
|
|
|
|
2016-07-13 12:06:49 +02:00
|
|
|
#define to_flat_binder_object(hdr) \
|
|
|
|
container_of(hdr, struct flat_binder_object, hdr)
|
|
|
|
|
|
|
|
#define to_binder_fd_object(hdr) container_of(hdr, struct binder_fd_object, hdr)
|
|
|
|
|
2016-09-30 14:10:07 +02:00
|
|
|
#define to_binder_buffer_object(hdr) \
|
|
|
|
container_of(hdr, struct binder_buffer_object, hdr)
|
|
|
|
|
2016-10-18 13:58:55 +02:00
|
|
|
#define to_binder_fd_array_object(hdr) \
|
|
|
|
container_of(hdr, struct binder_fd_array_object, hdr)
|
|
|
|
|
2011-11-30 20:18:14 +09:00
|
|
|
enum binder_stat_types {
|
|
|
|
BINDER_STAT_PROC,
|
|
|
|
BINDER_STAT_THREAD,
|
|
|
|
BINDER_STAT_NODE,
|
|
|
|
BINDER_STAT_REF,
|
|
|
|
BINDER_STAT_DEATH,
|
|
|
|
BINDER_STAT_TRANSACTION,
|
|
|
|
BINDER_STAT_TRANSACTION_COMPLETE,
|
|
|
|
BINDER_STAT_COUNT
|
|
|
|
};
|
|
|
|
|
|
|
|
struct binder_stats {
|
2016-10-13 16:36:15 -07:00
|
|
|
atomic_t br[_IOC_NR(BR_FAILED_REPLY) + 1];
|
|
|
|
atomic_t bc[_IOC_NR(BC_REPLY_SG) + 1];
|
2016-09-30 16:40:04 +02:00
|
|
|
atomic_t obj_created[BINDER_STAT_COUNT];
|
|
|
|
atomic_t obj_deleted[BINDER_STAT_COUNT];
|
|
|
|
};
|
|
|
|
|
2017-03-24 15:53:53 -07:00
|
|
|
static struct binder_stats binder_stats;
|
2011-11-30 20:18:14 +09:00
|
|
|
|
|
|
|
static inline void binder_stats_deleted(enum binder_stat_types type)
|
|
|
|
{
|
2016-10-13 16:36:15 -07:00
|
|
|
atomic_inc(&binder_stats.obj_deleted[type]);
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void binder_stats_created(enum binder_stat_types type)
|
|
|
|
{
|
2016-10-13 16:36:15 -07:00
|
|
|
atomic_inc(&binder_stats.obj_created[type]);
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
struct binder_transaction_log_entry {
|
|
|
|
int debug_id;
|
2017-05-24 13:33:28 -07:00
|
|
|
int debug_id_done;
|
2011-11-30 20:18:14 +09:00
|
|
|
int call_type;
|
|
|
|
int from_proc;
|
|
|
|
int from_thread;
|
|
|
|
int target_handle;
|
|
|
|
int to_proc;
|
|
|
|
int to_thread;
|
|
|
|
int to_node;
|
|
|
|
int data_size;
|
|
|
|
int offsets_size;
|
2017-03-22 17:19:52 -07:00
|
|
|
int return_error_line;
|
|
|
|
uint32_t return_error;
|
|
|
|
uint32_t return_error_param;
|
2016-10-17 15:17:31 +02:00
|
|
|
const char *context_name;
|
2011-11-30 20:18:14 +09:00
|
|
|
};
|
|
|
|
struct binder_transaction_log {
|
2017-05-24 13:33:28 -07:00
|
|
|
atomic_t cur;
|
|
|
|
bool full;
|
2011-11-30 20:18:14 +09:00
|
|
|
struct binder_transaction_log_entry entry[32];
|
|
|
|
};
|
2017-03-24 15:53:53 -07:00
|
|
|
static struct binder_transaction_log binder_transaction_log;
|
|
|
|
static struct binder_transaction_log binder_transaction_log_failed;
|
2011-11-30 20:18:14 +09:00
|
|
|
|
|
|
|
static struct binder_transaction_log_entry *binder_transaction_log_add(
|
|
|
|
struct binder_transaction_log *log)
|
|
|
|
{
|
|
|
|
struct binder_transaction_log_entry *e;
|
2017-05-24 13:33:28 -07:00
|
|
|
unsigned int cur = atomic_inc_return(&log->cur);
|
2014-05-01 01:30:23 +09:00
|
|
|
|
2017-05-24 13:33:28 -07:00
|
|
|
if (cur >= ARRAY_SIZE(log->entry))
|
2011-11-30 20:18:14 +09:00
|
|
|
log->full = 1;
|
2017-05-24 13:33:28 -07:00
|
|
|
e = &log->entry[cur % ARRAY_SIZE(log->entry)];
|
|
|
|
WRITE_ONCE(e->debug_id_done, 0);
|
|
|
|
/*
|
|
|
|
* write-barrier to synchronize access to e->debug_id_done.
|
|
|
|
* We make sure the initialized 0 value is seen before
|
|
|
|
* memset() other fields are zeroed by memset.
|
|
|
|
*/
|
|
|
|
smp_wmb();
|
|
|
|
memset(e, 0, sizeof(*e));
|
2011-11-30 20:18:14 +09:00
|
|
|
return e;
|
|
|
|
}
|
|
|
|
|
2016-09-30 15:51:48 +02:00
|
|
|
struct binder_context {
|
|
|
|
struct binder_node *binder_context_mgr_node;
|
2016-10-17 12:33:15 -07:00
|
|
|
struct mutex context_mgr_node_lock;
|
|
|
|
|
2016-09-30 15:51:48 +02:00
|
|
|
kuid_t binder_context_mgr_uid;
|
2016-10-17 15:17:31 +02:00
|
|
|
const char *name;
|
2016-09-30 15:51:48 +02:00
|
|
|
};
|
|
|
|
|
2016-09-30 16:08:09 +02:00
|
|
|
struct binder_device {
|
|
|
|
struct hlist_node hlist;
|
|
|
|
struct miscdevice miscdev;
|
|
|
|
struct binder_context context;
|
2016-09-30 15:51:48 +02:00
|
|
|
};
|
|
|
|
|
2016-10-20 10:33:00 -07:00
|
|
|
/**
|
|
|
|
* struct binder_work - work enqueued on a worklist
|
|
|
|
* @entry: node enqueued on list
|
|
|
|
* @type: type of work to be performed
|
|
|
|
*
|
|
|
|
* There are separate work lists for proc, thread, and node (async).
|
|
|
|
*/
|
2011-11-30 20:18:14 +09:00
|
|
|
struct binder_work {
|
|
|
|
struct list_head entry;
|
2016-10-20 10:33:00 -07:00
|
|
|
|
2011-11-30 20:18:14 +09:00
|
|
|
enum {
|
|
|
|
BINDER_WORK_TRANSACTION = 1,
|
|
|
|
BINDER_WORK_TRANSACTION_COMPLETE,
|
2017-04-21 17:35:12 -07:00
|
|
|
BINDER_WORK_RETURN_ERROR,
|
2011-11-30 20:18:14 +09:00
|
|
|
BINDER_WORK_NODE,
|
|
|
|
BINDER_WORK_DEAD_BINDER,
|
|
|
|
BINDER_WORK_DEAD_BINDER_AND_CLEAR,
|
|
|
|
BINDER_WORK_CLEAR_DEATH_NOTIFICATION,
|
|
|
|
} type;
|
|
|
|
};
|
|
|
|
|
2017-04-21 17:35:12 -07:00
|
|
|
struct binder_error {
|
|
|
|
struct binder_work work;
|
|
|
|
uint32_t cmd;
|
|
|
|
};
|
|
|
|
|
2017-05-29 16:44:24 -07:00
|
|
|
/**
|
|
|
|
* struct binder_node - binder node bookkeeping
|
|
|
|
* @debug_id: unique ID for debugging
|
|
|
|
* (invariant after initialized)
|
|
|
|
* @lock: lock for node fields
|
|
|
|
* @work: worklist element for node work
|
2016-10-20 10:33:00 -07:00
|
|
|
* (protected by @proc->inner_lock)
|
2017-05-29 16:44:24 -07:00
|
|
|
* @rb_node: element for proc->nodes tree
|
2017-06-12 12:07:26 -07:00
|
|
|
* (protected by @proc->inner_lock)
|
2017-05-29 16:44:24 -07:00
|
|
|
* @dead_node: element for binder_dead_nodes list
|
|
|
|
* (protected by binder_dead_nodes_lock)
|
|
|
|
* @proc: binder_proc that owns this node
|
|
|
|
* (invariant after initialized)
|
|
|
|
* @refs: list of references on this node
|
2017-06-08 13:45:59 -07:00
|
|
|
* (protected by @lock)
|
2017-05-29 16:44:24 -07:00
|
|
|
* @internal_strong_refs: used to take strong references when
|
|
|
|
* initiating a transaction
|
2017-03-21 13:06:01 -07:00
|
|
|
* (protected by @proc->inner_lock if @proc
|
|
|
|
* and by @lock)
|
2017-05-29 16:44:24 -07:00
|
|
|
* @local_weak_refs: weak user refs from local process
|
2017-03-21 13:06:01 -07:00
|
|
|
* (protected by @proc->inner_lock if @proc
|
|
|
|
* and by @lock)
|
2017-05-29 16:44:24 -07:00
|
|
|
* @local_strong_refs: strong user refs from local process
|
2017-03-21 13:06:01 -07:00
|
|
|
* (protected by @proc->inner_lock if @proc
|
|
|
|
* and by @lock)
|
2017-05-29 16:44:24 -07:00
|
|
|
* @tmp_refs: temporary kernel refs
|
2017-03-21 13:06:01 -07:00
|
|
|
* (protected by @proc->inner_lock while @proc
|
|
|
|
* is valid, and by binder_dead_nodes_lock
|
|
|
|
* if @proc is NULL. During inc/dec and node release
|
|
|
|
* it is also protected by @lock to provide safety
|
|
|
|
* as the node dies and @proc becomes NULL)
|
2017-05-29 16:44:24 -07:00
|
|
|
* @ptr: userspace pointer for node
|
|
|
|
* (invariant, no lock needed)
|
|
|
|
* @cookie: userspace cookie for node
|
|
|
|
* (invariant, no lock needed)
|
|
|
|
* @has_strong_ref: userspace notified of strong ref
|
2017-03-21 13:06:01 -07:00
|
|
|
* (protected by @proc->inner_lock if @proc
|
|
|
|
* and by @lock)
|
2017-05-29 16:44:24 -07:00
|
|
|
* @pending_strong_ref: userspace has acked notification of strong ref
|
2017-03-21 13:06:01 -07:00
|
|
|
* (protected by @proc->inner_lock if @proc
|
|
|
|
* and by @lock)
|
2017-05-29 16:44:24 -07:00
|
|
|
* @has_weak_ref: userspace notified of weak ref
|
2017-03-21 13:06:01 -07:00
|
|
|
* (protected by @proc->inner_lock if @proc
|
|
|
|
* and by @lock)
|
2017-05-29 16:44:24 -07:00
|
|
|
* @pending_weak_ref: userspace has acked notification of weak ref
|
2017-03-21 13:06:01 -07:00
|
|
|
* (protected by @proc->inner_lock if @proc
|
|
|
|
* and by @lock)
|
2017-05-29 16:44:24 -07:00
|
|
|
* @has_async_transaction: async transaction to node in progress
|
2017-06-08 13:45:59 -07:00
|
|
|
* (protected by @lock)
|
2017-06-07 09:29:14 -07:00
|
|
|
* @sched_policy: minimum scheduling policy for node
|
|
|
|
* (invariant after initialized)
|
2017-05-29 16:44:24 -07:00
|
|
|
* @accept_fds: file descriptor operations supported for node
|
|
|
|
* (invariant after initialized)
|
|
|
|
* @min_priority: minimum scheduling priority
|
|
|
|
* (invariant after initialized)
|
2017-06-23 10:13:43 -07:00
|
|
|
* @inherit_rt: inherit RT scheduling policy from caller
|
|
|
|
* (invariant after initialized)
|
2017-05-29 16:44:24 -07:00
|
|
|
* @async_todo: list of async work items
|
2016-10-20 10:33:00 -07:00
|
|
|
* (protected by @proc->inner_lock)
|
2017-05-29 16:44:24 -07:00
|
|
|
*
|
|
|
|
* Bookkeeping structure for binder nodes.
|
|
|
|
*/
|
2011-11-30 20:18:14 +09:00
|
|
|
struct binder_node {
|
|
|
|
int debug_id;
|
2017-05-29 16:44:24 -07:00
|
|
|
spinlock_t lock;
|
2011-11-30 20:18:14 +09:00
|
|
|
struct binder_work work;
|
|
|
|
union {
|
|
|
|
struct rb_node rb_node;
|
|
|
|
struct hlist_node dead_node;
|
|
|
|
};
|
|
|
|
struct binder_proc *proc;
|
|
|
|
struct hlist_head refs;
|
|
|
|
int internal_strong_refs;
|
|
|
|
int local_weak_refs;
|
|
|
|
int local_strong_refs;
|
2017-05-09 11:08:05 -07:00
|
|
|
int tmp_refs;
|
2014-02-21 14:40:26 -08:00
|
|
|
binder_uintptr_t ptr;
|
|
|
|
binder_uintptr_t cookie;
|
2017-03-21 13:06:01 -07:00
|
|
|
struct {
|
|
|
|
/*
|
|
|
|
* bitfield elements protected by
|
|
|
|
* proc inner_lock
|
|
|
|
*/
|
|
|
|
u8 has_strong_ref:1;
|
|
|
|
u8 pending_strong_ref:1;
|
|
|
|
u8 has_weak_ref:1;
|
|
|
|
u8 pending_weak_ref:1;
|
|
|
|
};
|
|
|
|
struct {
|
|
|
|
/*
|
|
|
|
* invariant after initialization
|
|
|
|
*/
|
2017-06-07 09:29:14 -07:00
|
|
|
u8 sched_policy:2;
|
2017-06-23 10:13:43 -07:00
|
|
|
u8 inherit_rt:1;
|
2017-03-21 13:06:01 -07:00
|
|
|
u8 accept_fds:1;
|
|
|
|
u8 min_priority;
|
|
|
|
};
|
|
|
|
bool has_async_transaction;
|
2011-11-30 20:18:14 +09:00
|
|
|
struct list_head async_todo;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct binder_ref_death {
|
2016-10-20 10:33:00 -07:00
|
|
|
/**
|
|
|
|
* @work: worklist element for death notifications
|
|
|
|
* (protected by inner_lock of the proc that
|
|
|
|
* this ref belongs to)
|
|
|
|
*/
|
2011-11-30 20:18:14 +09:00
|
|
|
struct binder_work work;
|
2014-02-21 14:40:26 -08:00
|
|
|
binder_uintptr_t cookie;
|
2011-11-30 20:18:14 +09:00
|
|
|
};
|
|
|
|
|
2017-05-08 09:16:27 -07:00
|
|
|
/**
|
|
|
|
* struct binder_ref_data - binder_ref counts and id
|
|
|
|
* @debug_id: unique ID for the ref
|
|
|
|
* @desc: unique userspace handle for ref
|
|
|
|
* @strong: strong ref count (debugging only if not locked)
|
|
|
|
* @weak: weak ref count (debugging only if not locked)
|
|
|
|
*
|
|
|
|
* Structure to hold ref count and ref id information. Since
|
|
|
|
* the actual ref can only be accessed with a lock, this structure
|
|
|
|
* is used to return information about the ref to callers of
|
|
|
|
* ref inc/dec functions.
|
|
|
|
*/
|
|
|
|
struct binder_ref_data {
|
|
|
|
int debug_id;
|
|
|
|
uint32_t desc;
|
|
|
|
int strong;
|
|
|
|
int weak;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct binder_ref - struct to track references on nodes
|
|
|
|
* @data: binder_ref_data containing id, handle, and current refcounts
|
|
|
|
* @rb_node_desc: node for lookup by @data.desc in proc's rb_tree
|
|
|
|
* @rb_node_node: node for lookup by @node in proc's rb_tree
|
|
|
|
* @node_entry: list entry for node->refs list in target node
|
2017-06-08 13:45:59 -07:00
|
|
|
* (protected by @node->lock)
|
2017-05-08 09:16:27 -07:00
|
|
|
* @proc: binder_proc containing ref
|
|
|
|
* @node: binder_node of target node. When cleaning up a
|
|
|
|
* ref for deletion in binder_cleanup_ref, a non-NULL
|
|
|
|
* @node indicates the node must be freed
|
|
|
|
* @death: pointer to death notification (ref_death) if requested
|
2017-05-22 11:26:23 -07:00
|
|
|
* (protected by @node->lock)
|
2017-05-08 09:16:27 -07:00
|
|
|
*
|
|
|
|
* Structure to track references from procA to target node (on procB). This
|
|
|
|
* structure is unsafe to access without holding @proc->outer_lock.
|
|
|
|
*/
|
2011-11-30 20:18:14 +09:00
|
|
|
struct binder_ref {
|
|
|
|
/* Lookups needed: */
|
|
|
|
/* node + proc => ref (transaction) */
|
|
|
|
/* desc + proc => ref (transaction, inc/dec ref) */
|
|
|
|
/* node => refs + procs (proc exit) */
|
2017-05-08 09:16:27 -07:00
|
|
|
struct binder_ref_data data;
|
2011-11-30 20:18:14 +09:00
|
|
|
struct rb_node rb_node_desc;
|
|
|
|
struct rb_node rb_node_node;
|
|
|
|
struct hlist_node node_entry;
|
|
|
|
struct binder_proc *proc;
|
|
|
|
struct binder_node *node;
|
|
|
|
struct binder_ref_death *death;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum binder_deferred_state {
|
2017-11-10 15:30:27 -08:00
|
|
|
BINDER_DEFERRED_FLUSH = 0x01,
|
|
|
|
BINDER_DEFERRED_RELEASE = 0x02,
|
2011-11-30 20:18:14 +09:00
|
|
|
};
|
|
|
|
|
2017-06-06 17:04:42 -07:00
|
|
|
/**
|
|
|
|
* struct binder_priority - scheduler policy and priority
|
|
|
|
* @sched_policy scheduler policy
|
|
|
|
* @prio [100..139] for SCHED_NORMAL, [0..99] for FIFO/RT
|
|
|
|
*
|
|
|
|
* The binder driver supports inheriting the following scheduler policies:
|
|
|
|
* SCHED_NORMAL
|
|
|
|
* SCHED_BATCH
|
|
|
|
* SCHED_FIFO
|
|
|
|
* SCHED_RR
|
|
|
|
*/
|
|
|
|
struct binder_priority {
|
|
|
|
unsigned int sched_policy;
|
|
|
|
int prio;
|
|
|
|
};
|
|
|
|
|
2017-05-29 16:44:24 -07:00
|
|
|
/**
|
|
|
|
* struct binder_proc - binder process bookkeeping
|
|
|
|
* @proc_node: element for binder_procs list
|
|
|
|
* @threads: rbtree of binder_threads in this proc
|
2017-05-25 15:52:17 -07:00
|
|
|
* (protected by @inner_lock)
|
2017-05-29 16:44:24 -07:00
|
|
|
* @nodes: rbtree of binder nodes associated with
|
|
|
|
* this proc ordered by node->ptr
|
2017-06-12 12:07:26 -07:00
|
|
|
* (protected by @inner_lock)
|
2017-05-29 16:44:24 -07:00
|
|
|
* @refs_by_desc: rbtree of refs ordered by ref->desc
|
2016-10-20 16:43:34 -07:00
|
|
|
* (protected by @outer_lock)
|
2017-05-29 16:44:24 -07:00
|
|
|
* @refs_by_node: rbtree of refs ordered by ref->node
|
2016-10-20 16:43:34 -07:00
|
|
|
* (protected by @outer_lock)
|
2017-06-02 11:15:44 -07:00
|
|
|
* @waiting_threads: threads currently waiting for proc work
|
|
|
|
* (protected by @inner_lock)
|
2017-05-29 16:44:24 -07:00
|
|
|
* @pid PID of group_leader of process
|
|
|
|
* (invariant after initialized)
|
|
|
|
* @tsk task_struct for group_leader of process
|
|
|
|
* (invariant after initialized)
|
|
|
|
* @deferred_work_node: element for binder_deferred_list
|
|
|
|
* (protected by binder_deferred_lock)
|
|
|
|
* @deferred_work: bitmap of deferred work to perform
|
|
|
|
* (protected by binder_deferred_lock)
|
|
|
|
* @is_dead: process is dead and awaiting free
|
|
|
|
* when outstanding transactions are cleaned up
|
2017-05-25 15:52:17 -07:00
|
|
|
* (protected by @inner_lock)
|
2017-05-29 16:44:24 -07:00
|
|
|
* @todo: list of work for this process
|
2016-10-20 10:33:00 -07:00
|
|
|
* (protected by @inner_lock)
|
2017-05-29 16:44:24 -07:00
|
|
|
* @stats: per-process binder statistics
|
|
|
|
* (atomics, no lock needed)
|
|
|
|
* @delivered_death: list of delivered death notification
|
2016-10-20 10:33:00 -07:00
|
|
|
* (protected by @inner_lock)
|
2017-05-29 16:44:24 -07:00
|
|
|
* @max_threads: cap on number of binder threads
|
2017-05-25 17:35:02 -07:00
|
|
|
* (protected by @inner_lock)
|
2017-05-29 16:44:24 -07:00
|
|
|
* @requested_threads: number of binder threads requested but not
|
|
|
|
* yet started. In current implementation, can
|
|
|
|
* only be 0 or 1.
|
2017-05-25 17:35:02 -07:00
|
|
|
* (protected by @inner_lock)
|
2017-05-29 16:44:24 -07:00
|
|
|
* @requested_threads_started: number binder threads started
|
2017-05-25 17:35:02 -07:00
|
|
|
* (protected by @inner_lock)
|
2017-05-29 16:44:24 -07:00
|
|
|
* @tmp_ref: temporary reference to indicate proc is in use
|
2017-05-25 15:52:17 -07:00
|
|
|
* (protected by @inner_lock)
|
2017-05-29 16:44:24 -07:00
|
|
|
* @default_priority: default scheduler priority
|
|
|
|
* (invariant after initialized)
|
|
|
|
* @debugfs_entry: debugfs node
|
|
|
|
* @alloc: binder allocator bookkeeping
|
|
|
|
* @context: binder_context for this proc
|
|
|
|
* (invariant after initialized)
|
|
|
|
* @inner_lock: can nest under outer_lock and/or node lock
|
|
|
|
* @outer_lock: no nesting under innor or node lock
|
|
|
|
* Lock order: 1) outer, 2) node, 3) inner
|
|
|
|
*
|
|
|
|
* Bookkeeping structure for binder processes
|
|
|
|
*/
|
2011-11-30 20:18:14 +09:00
|
|
|
struct binder_proc {
|
|
|
|
struct hlist_node proc_node;
|
|
|
|
struct rb_root threads;
|
|
|
|
struct rb_root nodes;
|
|
|
|
struct rb_root refs_by_desc;
|
|
|
|
struct rb_root refs_by_node;
|
2017-06-02 11:15:44 -07:00
|
|
|
struct list_head waiting_threads;
|
2011-11-30 20:18:14 +09:00
|
|
|
int pid;
|
|
|
|
struct task_struct *tsk;
|
|
|
|
struct hlist_node deferred_work_node;
|
|
|
|
int deferred_work;
|
2017-05-12 14:42:55 -07:00
|
|
|
bool is_dead;
|
2011-11-30 20:18:14 +09:00
|
|
|
|
|
|
|
struct list_head todo;
|
|
|
|
struct binder_stats stats;
|
|
|
|
struct list_head delivered_death;
|
|
|
|
int max_threads;
|
|
|
|
int requested_threads;
|
|
|
|
int requested_threads_started;
|
2017-05-12 14:42:55 -07:00
|
|
|
int tmp_ref;
|
2017-06-06 17:04:42 -07:00
|
|
|
struct binder_priority default_priority;
|
2009-04-28 20:57:50 -07:00
|
|
|
struct dentry *debugfs_entry;
|
2016-10-10 10:39:59 -07:00
|
|
|
struct binder_alloc alloc;
|
2016-09-30 15:51:48 +02:00
|
|
|
struct binder_context *context;
|
2017-05-29 16:44:24 -07:00
|
|
|
spinlock_t inner_lock;
|
|
|
|
spinlock_t outer_lock;
|
2011-11-30 20:18:14 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
BINDER_LOOPER_STATE_REGISTERED = 0x01,
|
|
|
|
BINDER_LOOPER_STATE_ENTERED = 0x02,
|
|
|
|
BINDER_LOOPER_STATE_EXITED = 0x04,
|
|
|
|
BINDER_LOOPER_STATE_INVALID = 0x08,
|
|
|
|
BINDER_LOOPER_STATE_WAITING = 0x10,
|
2017-06-02 11:15:44 -07:00
|
|
|
BINDER_LOOPER_STATE_POLL = 0x20,
|
2011-11-30 20:18:14 +09:00
|
|
|
};
|
|
|
|
|
2017-05-29 16:44:24 -07:00
|
|
|
/**
|
|
|
|
* struct binder_thread - binder thread bookkeeping
|
|
|
|
* @proc: binder process for this thread
|
|
|
|
* (invariant after initialization)
|
|
|
|
* @rb_node: element for proc->threads rbtree
|
2017-05-25 15:52:17 -07:00
|
|
|
* (protected by @proc->inner_lock)
|
2017-06-02 11:15:44 -07:00
|
|
|
* @waiting_thread_node: element for @proc->waiting_threads list
|
|
|
|
* (protected by @proc->inner_lock)
|
2017-05-29 16:44:24 -07:00
|
|
|
* @pid: PID for this thread
|
|
|
|
* (invariant after initialization)
|
|
|
|
* @looper: bitmap of looping state
|
|
|
|
* (only accessed by this thread)
|
|
|
|
* @looper_needs_return: looping thread needs to exit driver
|
|
|
|
* (no lock needed)
|
|
|
|
* @transaction_stack: stack of in-progress transactions for this thread
|
2017-06-02 13:36:52 -07:00
|
|
|
* (protected by @proc->inner_lock)
|
2017-05-29 16:44:24 -07:00
|
|
|
* @todo: list of work to do for this thread
|
2016-10-20 10:33:00 -07:00
|
|
|
* (protected by @proc->inner_lock)
|
2017-10-19 15:04:46 +02:00
|
|
|
* @process_todo: whether work in @todo should be processed
|
|
|
|
* (protected by @proc->inner_lock)
|
2017-05-29 16:44:24 -07:00
|
|
|
* @return_error: transaction errors reported by this thread
|
|
|
|
* (only accessed by this thread)
|
|
|
|
* @reply_error: transaction errors reported by target thread
|
2017-06-02 13:36:52 -07:00
|
|
|
* (protected by @proc->inner_lock)
|
2017-05-29 16:44:24 -07:00
|
|
|
* @wait: wait queue for thread work
|
|
|
|
* @stats: per-thread statistics
|
|
|
|
* (atomics, no lock needed)
|
|
|
|
* @tmp_ref: temporary reference to indicate thread is in use
|
|
|
|
* (atomic since @proc->inner_lock cannot
|
|
|
|
* always be acquired)
|
|
|
|
* @is_dead: thread is dead and awaiting free
|
|
|
|
* when outstanding transactions are cleaned up
|
2017-05-25 15:52:17 -07:00
|
|
|
* (protected by @proc->inner_lock)
|
2017-06-07 10:02:12 -07:00
|
|
|
* @task: struct task_struct for this thread
|
2017-05-29 16:44:24 -07:00
|
|
|
*
|
|
|
|
* Bookkeeping structure for binder threads.
|
|
|
|
*/
|
2011-11-30 20:18:14 +09:00
|
|
|
struct binder_thread {
|
|
|
|
struct binder_proc *proc;
|
|
|
|
struct rb_node rb_node;
|
2017-06-02 11:15:44 -07:00
|
|
|
struct list_head waiting_thread_node;
|
2011-11-30 20:18:14 +09:00
|
|
|
int pid;
|
2017-01-06 14:19:25 -08:00
|
|
|
int looper; /* only modified by this thread */
|
|
|
|
bool looper_need_return; /* can be written by other thread */
|
2011-11-30 20:18:14 +09:00
|
|
|
struct binder_transaction *transaction_stack;
|
|
|
|
struct list_head todo;
|
2017-10-19 15:04:46 +02:00
|
|
|
bool process_todo;
|
2017-04-21 17:35:12 -07:00
|
|
|
struct binder_error return_error;
|
|
|
|
struct binder_error reply_error;
|
2011-11-30 20:18:14 +09:00
|
|
|
wait_queue_head_t wait;
|
|
|
|
struct binder_stats stats;
|
2017-05-12 14:42:55 -07:00
|
|
|
atomic_t tmp_ref;
|
|
|
|
bool is_dead;
|
2017-06-07 10:02:12 -07:00
|
|
|
struct task_struct *task;
|
2011-11-30 20:18:14 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
struct binder_transaction {
|
|
|
|
int debug_id;
|
|
|
|
struct binder_work work;
|
|
|
|
struct binder_thread *from;
|
|
|
|
struct binder_transaction *from_parent;
|
|
|
|
struct binder_proc *to_proc;
|
|
|
|
struct binder_thread *to_thread;
|
|
|
|
struct binder_transaction *to_parent;
|
|
|
|
unsigned need_reply:1;
|
|
|
|
/* unsigned is_dead:1; */ /* not used at the moment */
|
|
|
|
|
|
|
|
struct binder_buffer *buffer;
|
|
|
|
unsigned int code;
|
|
|
|
unsigned int flags;
|
2017-06-06 17:04:42 -07:00
|
|
|
struct binder_priority priority;
|
|
|
|
struct binder_priority saved_priority;
|
2017-06-07 10:02:12 -07:00
|
|
|
bool set_priority_called;
|
2012-05-25 18:34:53 -06:00
|
|
|
kuid_t sender_euid;
|
2017-05-12 14:42:55 -07:00
|
|
|
/**
|
|
|
|
* @lock: protects @from, @to_proc, and @to_thread
|
|
|
|
*
|
|
|
|
* @from, @to_proc, and @to_thread can be set to NULL
|
|
|
|
* during thread teardown
|
|
|
|
*/
|
|
|
|
spinlock_t lock;
|
2011-11-30 20:18:14 +09:00
|
|
|
};
|
|
|
|
|
2017-05-29 16:44:24 -07:00
|
|
|
/**
|
|
|
|
* binder_proc_lock() - Acquire outer lock for given binder_proc
|
|
|
|
* @proc: struct binder_proc to acquire
|
|
|
|
*
|
|
|
|
* Acquires proc->outer_lock. Used to protect binder_ref
|
|
|
|
* structures associated with the given proc.
|
|
|
|
*/
|
|
|
|
#define binder_proc_lock(proc) _binder_proc_lock(proc, __LINE__)
|
|
|
|
static void
|
|
|
|
_binder_proc_lock(struct binder_proc *proc, int line)
|
|
|
|
{
|
|
|
|
binder_debug(BINDER_DEBUG_SPINLOCKS,
|
|
|
|
"%s: line=%d\n", __func__, line);
|
|
|
|
spin_lock(&proc->outer_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* binder_proc_unlock() - Release spinlock for given binder_proc
|
|
|
|
* @proc: struct binder_proc to acquire
|
|
|
|
*
|
|
|
|
* Release lock acquired via binder_proc_lock()
|
|
|
|
*/
|
|
|
|
#define binder_proc_unlock(_proc) _binder_proc_unlock(_proc, __LINE__)
|
|
|
|
static void
|
|
|
|
_binder_proc_unlock(struct binder_proc *proc, int line)
|
|
|
|
{
|
|
|
|
binder_debug(BINDER_DEBUG_SPINLOCKS,
|
|
|
|
"%s: line=%d\n", __func__, line);
|
|
|
|
spin_unlock(&proc->outer_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* binder_inner_proc_lock() - Acquire inner lock for given binder_proc
|
|
|
|
* @proc: struct binder_proc to acquire
|
|
|
|
*
|
|
|
|
* Acquires proc->inner_lock. Used to protect todo lists
|
|
|
|
*/
|
|
|
|
#define binder_inner_proc_lock(proc) _binder_inner_proc_lock(proc, __LINE__)
|
|
|
|
static void
|
|
|
|
_binder_inner_proc_lock(struct binder_proc *proc, int line)
|
|
|
|
{
|
|
|
|
binder_debug(BINDER_DEBUG_SPINLOCKS,
|
|
|
|
"%s: line=%d\n", __func__, line);
|
|
|
|
spin_lock(&proc->inner_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* binder_inner_proc_unlock() - Release inner lock for given binder_proc
|
|
|
|
* @proc: struct binder_proc to acquire
|
|
|
|
*
|
|
|
|
* Release lock acquired via binder_inner_proc_lock()
|
|
|
|
*/
|
|
|
|
#define binder_inner_proc_unlock(proc) _binder_inner_proc_unlock(proc, __LINE__)
|
|
|
|
static void
|
|
|
|
_binder_inner_proc_unlock(struct binder_proc *proc, int line)
|
|
|
|
{
|
|
|
|
binder_debug(BINDER_DEBUG_SPINLOCKS,
|
|
|
|
"%s: line=%d\n", __func__, line);
|
|
|
|
spin_unlock(&proc->inner_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* binder_node_lock() - Acquire spinlock for given binder_node
|
|
|
|
* @node: struct binder_node to acquire
|
|
|
|
*
|
|
|
|
* Acquires node->lock. Used to protect binder_node fields
|
|
|
|
*/
|
|
|
|
#define binder_node_lock(node) _binder_node_lock(node, __LINE__)
|
|
|
|
static void
|
|
|
|
_binder_node_lock(struct binder_node *node, int line)
|
|
|
|
{
|
|
|
|
binder_debug(BINDER_DEBUG_SPINLOCKS,
|
|
|
|
"%s: line=%d\n", __func__, line);
|
|
|
|
spin_lock(&node->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* binder_node_unlock() - Release spinlock for given binder_proc
|
|
|
|
* @node: struct binder_node to acquire
|
|
|
|
*
|
|
|
|
* Release lock acquired via binder_node_lock()
|
|
|
|
*/
|
|
|
|
#define binder_node_unlock(node) _binder_node_unlock(node, __LINE__)
|
|
|
|
static void
|
|
|
|
_binder_node_unlock(struct binder_node *node, int line)
|
|
|
|
{
|
|
|
|
binder_debug(BINDER_DEBUG_SPINLOCKS,
|
|
|
|
"%s: line=%d\n", __func__, line);
|
|
|
|
spin_unlock(&node->lock);
|
|
|
|
}
|
|
|
|
|
2017-06-08 13:45:59 -07:00
|
|
|
/**
|
|
|
|
* binder_node_inner_lock() - Acquire node and inner locks
|
|
|
|
* @node: struct binder_node to acquire
|
|
|
|
*
|
|
|
|
* Acquires node->lock. If node->proc also acquires
|
|
|
|
* proc->inner_lock. Used to protect binder_node fields
|
|
|
|
*/
|
|
|
|
#define binder_node_inner_lock(node) _binder_node_inner_lock(node, __LINE__)
|
|
|
|
static void
|
|
|
|
_binder_node_inner_lock(struct binder_node *node, int line)
|
|
|
|
{
|
|
|
|
binder_debug(BINDER_DEBUG_SPINLOCKS,
|
|
|
|
"%s: line=%d\n", __func__, line);
|
|
|
|
spin_lock(&node->lock);
|
|
|
|
if (node->proc)
|
|
|
|
binder_inner_proc_lock(node->proc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* binder_node_unlock() - Release node and inner locks
|
|
|
|
* @node: struct binder_node to acquire
|
|
|
|
*
|
|
|
|
* Release lock acquired via binder_node_lock()
|
|
|
|
*/
|
|
|
|
#define binder_node_inner_unlock(node) _binder_node_inner_unlock(node, __LINE__)
|
|
|
|
static void
|
|
|
|
_binder_node_inner_unlock(struct binder_node *node, int line)
|
|
|
|
{
|
|
|
|
struct binder_proc *proc = node->proc;
|
|
|
|
|
|
|
|
binder_debug(BINDER_DEBUG_SPINLOCKS,
|
|
|
|
"%s: line=%d\n", __func__, line);
|
|
|
|
if (proc)
|
|
|
|
binder_inner_proc_unlock(proc);
|
|
|
|
spin_unlock(&node->lock);
|
|
|
|
}
|
|
|
|
|
2016-10-20 10:33:00 -07:00
|
|
|
static bool binder_worklist_empty_ilocked(struct list_head *list)
|
|
|
|
{
|
|
|
|
return list_empty(list);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* binder_worklist_empty() - Check if no items on the work list
|
|
|
|
* @proc: binder_proc associated with list
|
|
|
|
* @list: list to check
|
|
|
|
*
|
|
|
|
* Return: true if there are no items on list, else false
|
|
|
|
*/
|
|
|
|
static bool binder_worklist_empty(struct binder_proc *proc,
|
|
|
|
struct list_head *list)
|
|
|
|
{
|
|
|
|
bool ret;
|
|
|
|
|
|
|
|
binder_inner_proc_lock(proc);
|
|
|
|
ret = binder_worklist_empty_ilocked(list);
|
|
|
|
binder_inner_proc_unlock(proc);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-10-19 15:04:46 +02:00
|
|
|
/**
|
|
|
|
* binder_enqueue_work_ilocked() - Add an item to the work list
|
|
|
|
* @work: struct binder_work to add to list
|
|
|
|
* @target_list: list to add work to
|
|
|
|
*
|
|
|
|
* Adds the work to the specified list. Asserts that work
|
|
|
|
* is not already on a list.
|
|
|
|
*
|
|
|
|
* Requires the proc->inner_lock to be held.
|
|
|
|
*/
|
2016-10-20 10:33:00 -07:00
|
|
|
static void
|
|
|
|
binder_enqueue_work_ilocked(struct binder_work *work,
|
|
|
|
struct list_head *target_list)
|
|
|
|
{
|
|
|
|
BUG_ON(target_list == NULL);
|
|
|
|
BUG_ON(work->entry.next && !list_empty(&work->entry));
|
|
|
|
list_add_tail(&work->entry, target_list);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-11-13 09:55:21 +01:00
|
|
|
* binder_enqueue_deferred_thread_work_ilocked() - Add deferred thread work
|
2017-10-19 15:04:46 +02:00
|
|
|
* @thread: thread to queue work to
|
2016-10-20 10:33:00 -07:00
|
|
|
* @work: struct binder_work to add to list
|
|
|
|
*
|
2017-10-19 15:04:46 +02:00
|
|
|
* Adds the work to the todo list of the thread. Doesn't set the process_todo
|
|
|
|
* flag, which means that (if it wasn't already set) the thread will go to
|
|
|
|
* sleep without handling this work when it calls read.
|
|
|
|
*
|
|
|
|
* Requires the proc->inner_lock to be held.
|
2016-10-20 10:33:00 -07:00
|
|
|
*/
|
|
|
|
static void
|
2017-11-13 09:55:21 +01:00
|
|
|
binder_enqueue_deferred_thread_work_ilocked(struct binder_thread *thread,
|
|
|
|
struct binder_work *work)
|
2016-10-20 10:33:00 -07:00
|
|
|
{
|
2017-10-19 15:04:46 +02:00
|
|
|
binder_enqueue_work_ilocked(work, &thread->todo);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* binder_enqueue_thread_work_ilocked() - Add an item to the thread work list
|
|
|
|
* @thread: thread to queue work to
|
|
|
|
* @work: struct binder_work to add to list
|
|
|
|
*
|
|
|
|
* Adds the work to the todo list of the thread, and enables processing
|
|
|
|
* of the todo queue.
|
|
|
|
*
|
|
|
|
* Requires the proc->inner_lock to be held.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
binder_enqueue_thread_work_ilocked(struct binder_thread *thread,
|
|
|
|
struct binder_work *work)
|
|
|
|
{
|
|
|
|
binder_enqueue_work_ilocked(work, &thread->todo);
|
|
|
|
thread->process_todo = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* binder_enqueue_thread_work() - Add an item to the thread work list
|
|
|
|
* @thread: thread to queue work to
|
|
|
|
* @work: struct binder_work to add to list
|
|
|
|
*
|
|
|
|
* Adds the work to the todo list of the thread, and enables processing
|
|
|
|
* of the todo queue.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
binder_enqueue_thread_work(struct binder_thread *thread,
|
|
|
|
struct binder_work *work)
|
|
|
|
{
|
|
|
|
binder_inner_proc_lock(thread->proc);
|
|
|
|
binder_enqueue_thread_work_ilocked(thread, work);
|
|
|
|
binder_inner_proc_unlock(thread->proc);
|
2016-10-20 10:33:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
binder_dequeue_work_ilocked(struct binder_work *work)
|
|
|
|
{
|
|
|
|
list_del_init(&work->entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* binder_dequeue_work() - Removes an item from the work list
|
|
|
|
* @proc: binder_proc associated with list
|
|
|
|
* @work: struct binder_work to remove from list
|
|
|
|
*
|
|
|
|
* Removes the specified work item from whatever list it is on.
|
|
|
|
* Can safely be called if work is not on any list.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
binder_dequeue_work(struct binder_proc *proc, struct binder_work *work)
|
|
|
|
{
|
|
|
|
binder_inner_proc_lock(proc);
|
|
|
|
binder_dequeue_work_ilocked(work);
|
|
|
|
binder_inner_proc_unlock(proc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct binder_work *binder_dequeue_work_head_ilocked(
|
|
|
|
struct list_head *list)
|
|
|
|
{
|
|
|
|
struct binder_work *w;
|
|
|
|
|
|
|
|
w = list_first_entry_or_null(list, struct binder_work, entry);
|
|
|
|
if (w)
|
|
|
|
list_del_init(&w->entry);
|
|
|
|
return w;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* binder_dequeue_work_head() - Dequeues the item at head of list
|
|
|
|
* @proc: binder_proc associated with list
|
|
|
|
* @list: list to dequeue head
|
|
|
|
*
|
|
|
|
* Removes the head of the list if there are items on the list
|
|
|
|
*
|
|
|
|
* Return: pointer dequeued binder_work, NULL if list was empty
|
|
|
|
*/
|
|
|
|
static struct binder_work *binder_dequeue_work_head(
|
|
|
|
struct binder_proc *proc,
|
|
|
|
struct list_head *list)
|
|
|
|
{
|
|
|
|
struct binder_work *w;
|
|
|
|
|
|
|
|
binder_inner_proc_lock(proc);
|
|
|
|
w = binder_dequeue_work_head_ilocked(list);
|
|
|
|
binder_inner_proc_unlock(proc);
|
|
|
|
return w;
|
|
|
|
}
|
|
|
|
|
2011-11-30 20:18:14 +09:00
|
|
|
static void
|
|
|
|
binder_defer_work(struct binder_proc *proc, enum binder_deferred_state defer);
|
2017-05-12 14:42:55 -07:00
|
|
|
static void binder_free_thread(struct binder_thread *thread);
|
|
|
|
static void binder_free_proc(struct binder_proc *proc);
|
2017-06-12 12:07:26 -07:00
|
|
|
static void binder_inc_node_tmpref_ilocked(struct binder_node *node);
|
2011-11-30 20:18:14 +09:00
|
|
|
|
2017-11-10 15:30:27 -08:00
|
|
|
struct files_struct *binder_get_files_struct(struct binder_proc *proc)
|
|
|
|
{
|
|
|
|
return get_files_struct(proc->tsk);
|
|
|
|
}
|
|
|
|
|
2012-08-17 16:39:36 +05:30
|
|
|
static int task_get_unused_fd_flags(struct binder_proc *proc, int flags)
|
2011-11-30 20:18:14 +09:00
|
|
|
{
|
2017-11-10 15:30:27 -08:00
|
|
|
struct files_struct *files;
|
2011-11-30 20:18:14 +09:00
|
|
|
unsigned long rlim_cur;
|
|
|
|
unsigned long irqs;
|
2017-11-10 15:30:27 -08:00
|
|
|
int ret;
|
2011-11-30 20:18:14 +09:00
|
|
|
|
2017-11-10 15:30:27 -08:00
|
|
|
files = binder_get_files_struct(proc);
|
2011-11-30 20:18:14 +09:00
|
|
|
if (files == NULL)
|
|
|
|
return -ESRCH;
|
|
|
|
|
2017-11-10 15:30:27 -08:00
|
|
|
if (!lock_task_sighand(proc->tsk, &irqs)) {
|
|
|
|
ret = -EMFILE;
|
|
|
|
goto err;
|
|
|
|
}
|
2012-08-17 16:39:37 +05:30
|
|
|
|
2012-08-12 17:27:30 -04:00
|
|
|
rlim_cur = task_rlimit(proc->tsk, RLIMIT_NOFILE);
|
|
|
|
unlock_task_sighand(proc->tsk, &irqs);
|
2011-11-30 20:18:14 +09:00
|
|
|
|
2017-11-10 15:30:27 -08:00
|
|
|
ret = __alloc_fd(files, 0, rlim_cur, flags);
|
|
|
|
err:
|
|
|
|
put_files_struct(files);
|
|
|
|
return ret;
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* copied from fd_install
|
|
|
|
*/
|
|
|
|
static void task_fd_install(
|
|
|
|
struct binder_proc *proc, unsigned int fd, struct file *file)
|
|
|
|
{
|
2017-11-10 15:30:27 -08:00
|
|
|
struct files_struct *files = binder_get_files_struct(proc);
|
|
|
|
|
|
|
|
if (files) {
|
|
|
|
__fd_install(files, fd, file);
|
|
|
|
put_files_struct(files);
|
|
|
|
}
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* copied from sys_close
|
|
|
|
*/
|
|
|
|
static long task_close_fd(struct binder_proc *proc, unsigned int fd)
|
|
|
|
{
|
2017-11-10 15:30:27 -08:00
|
|
|
struct files_struct *files = binder_get_files_struct(proc);
|
2011-11-30 20:18:14 +09:00
|
|
|
int retval;
|
|
|
|
|
2017-11-10 15:30:27 -08:00
|
|
|
if (files == NULL)
|
2011-11-30 20:18:14 +09:00
|
|
|
return -ESRCH;
|
|
|
|
|
2017-11-10 15:30:27 -08:00
|
|
|
retval = __close_fd(files, fd);
|
2011-11-30 20:18:14 +09:00
|
|
|
/* can't restart close syscall because file table entry was cleared */
|
|
|
|
if (unlikely(retval == -ERESTARTSYS ||
|
|
|
|
retval == -ERESTARTNOINTR ||
|
|
|
|
retval == -ERESTARTNOHAND ||
|
|
|
|
retval == -ERESTART_RESTARTBLOCK))
|
|
|
|
retval = -EINTR;
|
2017-11-10 15:30:27 -08:00
|
|
|
put_files_struct(files);
|
2011-11-30 20:18:14 +09:00
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2017-06-02 11:15:44 -07:00
|
|
|
static bool binder_has_work_ilocked(struct binder_thread *thread,
|
|
|
|
bool do_proc_work)
|
2012-10-16 15:29:53 -07:00
|
|
|
{
|
2017-10-19 15:04:46 +02:00
|
|
|
return thread->process_todo ||
|
2017-06-02 11:15:44 -07:00
|
|
|
thread->looper_need_return ||
|
|
|
|
(do_proc_work &&
|
|
|
|
!binder_worklist_empty_ilocked(&thread->proc->todo));
|
2012-10-16 15:29:53 -07:00
|
|
|
}
|
|
|
|
|
2017-06-02 11:15:44 -07:00
|
|
|
static bool binder_has_work(struct binder_thread *thread, bool do_proc_work)
|
2012-10-16 15:29:53 -07:00
|
|
|
{
|
2017-06-02 11:15:44 -07:00
|
|
|
bool has_work;
|
2015-09-15 10:49:46 -07:00
|
|
|
|
2017-06-02 11:15:44 -07:00
|
|
|
binder_inner_proc_lock(thread->proc);
|
|
|
|
has_work = binder_has_work_ilocked(thread, do_proc_work);
|
|
|
|
binder_inner_proc_unlock(thread->proc);
|
2014-05-01 01:30:23 +09:00
|
|
|
|
2017-06-02 11:15:44 -07:00
|
|
|
return has_work;
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
|
|
|
|
2017-06-02 11:15:44 -07:00
|
|
|
static bool binder_available_for_proc_work_ilocked(struct binder_thread *thread)
|
2011-11-30 20:18:14 +09:00
|
|
|
{
|
2017-06-02 11:15:44 -07:00
|
|
|
return !thread->transaction_stack &&
|
|
|
|
binder_worklist_empty_ilocked(&thread->todo) &&
|
|
|
|
(thread->looper & (BINDER_LOOPER_STATE_ENTERED |
|
|
|
|
BINDER_LOOPER_STATE_REGISTERED));
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
|
|
|
|
2017-06-02 11:15:44 -07:00
|
|
|
static void binder_wakeup_poll_threads_ilocked(struct binder_proc *proc,
|
|
|
|
bool sync)
|
2011-11-30 20:18:14 +09:00
|
|
|
{
|
2017-06-02 11:15:44 -07:00
|
|
|
struct rb_node *n;
|
|
|
|
struct binder_thread *thread;
|
|
|
|
|
|
|
|
for (n = rb_first(&proc->threads); n != NULL; n = rb_next(n)) {
|
|
|
|
thread = rb_entry(n, struct binder_thread, rb_node);
|
|
|
|
if (thread->looper & BINDER_LOOPER_STATE_POLL &&
|
|
|
|
binder_available_for_proc_work_ilocked(thread)) {
|
|
|
|
if (sync)
|
|
|
|
wake_up_interruptible_sync(&thread->wait);
|
|
|
|
else
|
|
|
|
wake_up_interruptible(&thread->wait);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-11-30 20:18:14 +09:00
|
|
|
|
2017-06-06 15:17:46 -07:00
|
|
|
/**
|
|
|
|
* binder_select_thread_ilocked() - selects a thread for doing proc work.
|
|
|
|
* @proc: process to select a thread from
|
|
|
|
*
|
|
|
|
* Note that calling this function moves the thread off the waiting_threads
|
|
|
|
* list, so it can only be woken up by the caller of this function, or a
|
|
|
|
* signal. Therefore, callers *should* always wake up the thread this function
|
|
|
|
* returns.
|
|
|
|
*
|
|
|
|
* Return: If there's a thread currently waiting for process work,
|
|
|
|
* returns that thread. Otherwise returns NULL.
|
|
|
|
*/
|
|
|
|
static struct binder_thread *
|
|
|
|
binder_select_thread_ilocked(struct binder_proc *proc)
|
2017-06-02 11:15:44 -07:00
|
|
|
{
|
|
|
|
struct binder_thread *thread;
|
2011-11-30 20:18:14 +09:00
|
|
|
|
2017-07-27 23:52:24 +02:00
|
|
|
assert_spin_locked(&proc->inner_lock);
|
2017-06-02 11:15:44 -07:00
|
|
|
thread = list_first_entry_or_null(&proc->waiting_threads,
|
|
|
|
struct binder_thread,
|
|
|
|
waiting_thread_node);
|
2011-11-30 20:18:14 +09:00
|
|
|
|
2017-06-06 15:17:46 -07:00
|
|
|
if (thread)
|
2017-06-02 11:15:44 -07:00
|
|
|
list_del_init(&thread->waiting_thread_node);
|
2011-11-30 20:18:14 +09:00
|
|
|
|
2017-06-06 15:17:46 -07:00
|
|
|
return thread;
|
|
|
|
}
|
2011-11-30 20:18:14 +09:00
|
|
|
|
2017-06-06 15:17:46 -07:00
|
|
|
/**
|
|
|
|
* binder_wakeup_thread_ilocked() - wakes up a thread for doing proc work.
|
|
|
|
* @proc: process to wake up a thread in
|
|
|
|
* @thread: specific thread to wake-up (may be NULL)
|
|
|
|
* @sync: whether to do a synchronous wake-up
|
|
|
|
*
|
|
|
|
* This function wakes up a thread in the @proc process.
|
|
|
|
* The caller may provide a specific thread to wake-up in
|
|
|
|
* the @thread parameter. If @thread is NULL, this function
|
|
|
|
* will wake up threads that have called poll().
|
|
|
|
*
|
|
|
|
* Note that for this function to work as expected, callers
|
|
|
|
* should first call binder_select_thread() to find a thread
|
|
|
|
* to handle the work (if they don't have a thread already),
|
|
|
|
* and pass the result into the @thread parameter.
|
|
|
|
*/
|
|
|
|
static void binder_wakeup_thread_ilocked(struct binder_proc *proc,
|
|
|
|
struct binder_thread *thread,
|
|
|
|
bool sync)
|
|
|
|
{
|
2017-07-27 23:52:24 +02:00
|
|
|
assert_spin_locked(&proc->inner_lock);
|
2011-11-30 20:18:14 +09:00
|
|
|
|
2017-06-06 15:17:46 -07:00
|
|
|
if (thread) {
|
2017-06-02 11:15:44 -07:00
|
|
|
if (sync)
|
|
|
|
wake_up_interruptible_sync(&thread->wait);
|
2011-11-30 20:18:14 +09:00
|
|
|
else
|
2017-06-02 11:15:44 -07:00
|
|
|
wake_up_interruptible(&thread->wait);
|
|
|
|
return;
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
2017-06-02 11:15:44 -07:00
|
|
|
|
|
|
|
/* Didn't find a thread waiting for proc work; this can happen
|
|
|
|
* in two scenarios:
|
|
|
|
* 1. All threads are busy handling transactions
|
|
|
|
* In that case, one of those threads should call back into
|
|
|
|
* the kernel driver soon and pick up this work.
|
|
|
|
* 2. Threads are using the (e)poll interface, in which case
|
|
|
|
* they may be blocked on the waitqueue without having been
|
|
|
|
* added to waiting_threads. For this case, we just iterate
|
|
|
|
* over all threads not handling transaction work, and
|
|
|
|
* wake them all up. We wake all because we don't know whether
|
|
|
|
* a thread that called into (e)poll is handling non-binder
|
|
|
|
* work currently.
|
|
|
|
*/
|
|
|
|
binder_wakeup_poll_threads_ilocked(proc, sync);
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
|
|
|
|
2017-06-06 15:17:46 -07:00
|
|
|
static void binder_wakeup_proc_ilocked(struct binder_proc *proc)
|
2011-11-30 20:18:14 +09:00
|
|
|
{
|
2017-06-06 15:17:46 -07:00
|
|
|
struct binder_thread *thread = binder_select_thread_ilocked(proc);
|
2011-11-30 20:18:14 +09:00
|
|
|
|
2017-06-06 15:17:46 -07:00
|
|
|
binder_wakeup_thread_ilocked(proc, thread, /* sync = */false);
|
|
|
|
}
|
2011-11-30 20:18:14 +09:00
|
|
|
|
2017-06-06 17:04:42 -07:00
|
|
|
static bool is_rt_policy(int policy)
|
|
|
|
{
|
|
|
|
return policy == SCHED_FIFO || policy == SCHED_RR;
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
|
|
|
|
2017-06-06 17:04:42 -07:00
|
|
|
static bool is_fair_policy(int policy)
|
2011-11-30 20:18:14 +09:00
|
|
|
{
|
2017-06-06 17:04:42 -07:00
|
|
|
return policy == SCHED_NORMAL || policy == SCHED_BATCH;
|
|
|
|
}
|
2011-11-30 20:18:14 +09:00
|
|
|
|
2017-06-06 17:04:42 -07:00
|
|
|
static bool binder_supported_policy(int policy)
|
|
|
|
{
|
|
|
|
return is_fair_policy(policy) || is_rt_policy(policy);
|
|
|
|
}
|
2011-11-30 20:18:14 +09:00
|
|
|
|
2017-06-06 17:04:42 -07:00
|
|
|
static int to_userspace_prio(int policy, int kernel_priority)
|
|
|
|
{
|
|
|
|
if (is_fair_policy(policy))
|
|
|
|
return PRIO_TO_NICE(kernel_priority);
|
|
|
|
else
|
|
|
|
return MAX_USER_RT_PRIO - 1 - kernel_priority;
|
|
|
|
}
|
2011-11-30 20:18:14 +09:00
|
|
|
|
2017-06-06 17:04:42 -07:00
|
|
|
static int to_kernel_prio(int policy, int user_priority)
|
|
|
|
{
|
|
|
|
if (is_fair_policy(policy))
|
|
|
|
return NICE_TO_PRIO(user_priority);
|
|
|
|
else
|
|
|
|
return MAX_USER_RT_PRIO - 1 - user_priority;
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
|
|
|
|
2017-05-26 10:48:56 -07:00
|
|
|
static void binder_do_set_priority(struct task_struct *task,
|
|
|
|
struct binder_priority desired,
|
|
|
|
bool verify)
|
2011-11-30 20:18:14 +09:00
|
|
|
{
|
2017-06-06 17:04:42 -07:00
|
|
|
int priority; /* user-space prio value */
|
|
|
|
bool has_cap_nice;
|
|
|
|
unsigned int policy = desired.sched_policy;
|
2011-11-30 20:18:14 +09:00
|
|
|
|
2017-06-06 17:04:42 -07:00
|
|
|
if (task->policy == policy && task->normal_prio == desired.prio)
|
2011-11-30 20:18:14 +09:00
|
|
|
return;
|
|
|
|
|
2017-06-06 17:04:42 -07:00
|
|
|
has_cap_nice = has_capability_noaudit(task, CAP_SYS_NICE);
|
2011-11-30 20:18:14 +09:00
|
|
|
|
2017-06-06 17:04:42 -07:00
|
|
|
priority = to_userspace_prio(policy, desired.prio);
|
2012-10-16 15:29:53 -07:00
|
|
|
|
2017-05-26 10:48:56 -07:00
|
|
|
if (verify && is_rt_policy(policy) && !has_cap_nice) {
|
2017-06-06 17:04:42 -07:00
|
|
|
long max_rtprio = task_rlimit(task, RLIMIT_RTPRIO);
|
|
|
|
|
|
|
|
if (max_rtprio == 0) {
|
|
|
|
policy = SCHED_NORMAL;
|
|
|
|
priority = MIN_NICE;
|
|
|
|
} else if (priority > max_rtprio) {
|
|
|
|
priority = max_rtprio;
|
2012-02-01 15:29:13 -08:00
|
|
|
}
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
|
|
|
|
2017-05-26 10:48:56 -07:00
|
|
|
if (verify && is_fair_policy(policy) && !has_cap_nice) {
|
2017-06-06 17:04:42 -07:00
|
|
|
long min_nice = rlimit_to_nice(task_rlimit(task, RLIMIT_NICE));
|
2011-11-30 20:18:14 +09:00
|
|
|
|
2017-06-06 17:04:42 -07:00
|
|
|
if (min_nice > MAX_NICE) {
|
|
|
|
binder_user_error("%d RLIMIT_NICE not set\n",
|
|
|
|
task->pid);
|
|
|
|
return;
|
|
|
|
} else if (priority < min_nice) {
|
|
|
|
priority = min_nice;
|
|
|
|
}
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
|
|
|
|
2017-06-06 17:04:42 -07:00
|
|
|
if (policy != desired.sched_policy ||
|
|
|
|
to_kernel_prio(policy, priority) != desired.prio)
|
|
|
|
binder_debug(BINDER_DEBUG_PRIORITY_CAP,
|
|
|
|
"%d: priority %d not allowed, using %d instead\n",
|
|
|
|
task->pid, desired.prio,
|
|
|
|
to_kernel_prio(policy, priority));
|
2014-05-01 01:30:23 +09:00
|
|
|
|
2017-05-08 09:33:22 -07:00
|
|
|
trace_binder_set_priority(task->tgid, task->pid, task->normal_prio,
|
|
|
|
to_kernel_prio(policy, priority),
|
|
|
|
desired.prio);
|
|
|
|
|
2017-06-06 17:04:42 -07:00
|
|
|
/* Set the actual priority */
|
|
|
|
if (task->policy != policy || is_rt_policy(policy)) {
|
|
|
|
struct sched_param params;
|
2011-11-30 20:18:14 +09:00
|
|
|
|
2017-06-06 17:04:42 -07:00
|
|
|
params.sched_priority = is_rt_policy(policy) ? priority : 0;
|
2011-11-30 20:18:14 +09:00
|
|
|
|
2017-06-06 17:04:42 -07:00
|
|
|
sched_setscheduler_nocheck(task,
|
|
|
|
policy | SCHED_RESET_ON_FORK,
|
|
|
|
¶ms);
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
2017-06-06 17:04:42 -07:00
|
|
|
if (is_fair_policy(policy))
|
|
|
|
set_user_nice(task, priority);
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
|
|
|
|
2017-05-26 10:48:56 -07:00
|
|
|
static void binder_set_priority(struct task_struct *task,
|
|
|
|
struct binder_priority desired)
|
2011-11-30 20:18:14 +09:00
|
|
|
{
|
2017-05-26 10:48:56 -07:00
|
|
|
binder_do_set_priority(task, desired, /* verify = */ true);
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
|
|
|
|
2017-05-26 10:48:56 -07:00
|
|
|
static void binder_restore_priority(struct task_struct *task,
|
|
|
|
struct binder_priority desired)
|
2011-11-30 20:18:14 +09:00
|
|
|
{
|
2017-05-26 10:48:56 -07:00
|
|
|
binder_do_set_priority(task, desired, /* verify = */ false);
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
|
|
|
|
2017-06-07 10:02:12 -07:00
|
|
|
static void binder_transaction_priority(struct task_struct *task,
|
|
|
|
struct binder_transaction *t,
|
2017-06-23 10:13:43 -07:00
|
|
|
struct binder_priority node_prio,
|
|
|
|
bool inherit_rt)
|
2011-11-30 20:18:14 +09:00
|
|
|
{
|
2017-09-27 15:12:25 +08:00
|
|
|
struct binder_priority desired_prio = t->priority;
|
2011-11-30 20:18:14 +09:00
|
|
|
|
2017-06-07 10:02:12 -07:00
|
|
|
if (t->set_priority_called)
|
|
|
|
return;
|
2011-11-30 20:18:14 +09:00
|
|
|
|
2017-06-07 10:02:12 -07:00
|
|
|
t->set_priority_called = true;
|
|
|
|
t->saved_priority.sched_policy = task->policy;
|
|
|
|
t->saved_priority.prio = task->normal_prio;
|
2011-11-30 20:18:14 +09:00
|
|
|
|
2017-06-23 10:13:43 -07:00
|
|
|
if (!inherit_rt && is_rt_policy(desired_prio.sched_policy)) {
|
|
|
|
desired_prio.prio = NICE_TO_PRIO(0);
|
|
|
|
desired_prio.sched_policy = SCHED_NORMAL;
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
|
|
|
|
2017-06-07 10:02:12 -07:00
|
|
|
if (node_prio.prio < t->priority.prio ||
|
|
|
|
(node_prio.prio == t->priority.prio &&
|
|
|
|
node_prio.sched_policy == SCHED_FIFO)) {
|
|
|
|
/*
|
|
|
|
* In case the minimum priority on the node is
|
|
|
|
* higher (lower value), use that priority. If
|
|
|
|
* the priority is the same, but the node uses
|
|
|
|
* SCHED_FIFO, prefer SCHED_FIFO, since it can
|
|
|
|
* run unbounded, unlike SCHED_RR.
|
|
|
|
*/
|
|
|
|
desired_prio = node_prio;
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
2017-06-07 10:02:12 -07:00
|
|
|
|
|
|
|
binder_set_priority(task, desired_prio);
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
|
|
|
|
2017-06-12 12:07:26 -07:00
|
|
|
static struct binder_node *binder_get_node_ilocked(struct binder_proc *proc,
|
|
|
|
binder_uintptr_t ptr)
|
2011-11-30 20:18:14 +09:00
|
|
|
{
|
|
|
|
struct rb_node *n = proc->nodes.rb_node;
|
|
|
|
struct binder_node *node;
|
|
|
|
|
2017-07-27 23:52:24 +02:00
|
|
|
assert_spin_locked(&proc->inner_lock);
|
2017-06-12 12:07:26 -07:00
|
|
|
|
2011-11-30 20:18:14 +09:00
|
|
|
while (n) {
|
|
|
|
node = rb_entry(n, struct binder_node, rb_node);
|
|
|
|
|
|
|
|
if (ptr < node->ptr)
|
|
|
|
n = n->rb_left;
|
|
|
|
else if (ptr > node->ptr)
|
|
|
|
n = n->rb_right;
|
2017-05-09 11:08:05 -07:00
|
|
|
else {
|
|
|
|
/*
|
|
|
|
* take an implicit weak reference
|
|
|
|
* to ensure node stays alive until
|
|
|
|
* call to binder_put_node()
|
|
|
|
*/
|
2017-06-12 12:07:26 -07:00
|
|
|
binder_inc_node_tmpref_ilocked(node);
|
2011-11-30 20:18:14 +09:00
|
|
|
return node;
|
2017-05-09 11:08:05 -07:00
|
|
|
}
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-06-12 12:07:26 -07:00
|
|
|
static struct binder_node *binder_get_node(struct binder_proc *proc,
|
|
|
|
binder_uintptr_t ptr)
|
|
|
|
{
|
|
|
|
struct binder_node *node;
|
|
|
|
|
|
|
|
binder_inner_proc_lock(proc);
|
|
|
|
node = binder_get_node_ilocked(proc, ptr);
|
|
|
|
binder_inner_proc_unlock(proc);
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct binder_node *binder_init_node_ilocked(
|
|
|
|
struct binder_proc *proc,
|
|
|
|
struct binder_node *new_node,
|
|
|
|
struct flat_binder_object *fp)
|
2011-11-30 20:18:14 +09:00
|
|
|
{
|
|
|
|
struct rb_node **p = &proc->nodes.rb_node;
|
|
|
|
struct rb_node *parent = NULL;
|
|
|
|
struct binder_node *node;
|
2017-06-08 13:45:59 -07:00
|
|
|
binder_uintptr_t ptr = fp ? fp->binder : 0;
|
|
|
|
binder_uintptr_t cookie = fp ? fp->cookie : 0;
|
|
|
|
__u32 flags = fp ? fp->flags : 0;
|
2017-06-07 09:29:14 -07:00
|
|
|
s8 priority;
|
2011-11-30 20:18:14 +09:00
|
|
|
|
2017-07-27 23:52:24 +02:00
|
|
|
assert_spin_locked(&proc->inner_lock);
|
|
|
|
|
2011-11-30 20:18:14 +09:00
|
|
|
while (*p) {
|
2017-06-12 12:07:26 -07:00
|
|
|
|
2011-11-30 20:18:14 +09:00
|
|
|
parent = *p;
|
|
|
|
node = rb_entry(parent, struct binder_node, rb_node);
|
|
|
|
|
|
|
|
if (ptr < node->ptr)
|
|
|
|
p = &(*p)->rb_left;
|
|
|
|
else if (ptr > node->ptr)
|
|
|
|
p = &(*p)->rb_right;
|
2017-06-12 12:07:26 -07:00
|
|
|
else {
|
|
|
|
/*
|
|
|
|
* A matching node is already in
|
|
|
|
* the rb tree. Abandon the init
|
|
|
|
* and return it.
|
|
|
|
*/
|
|
|
|
binder_inc_node_tmpref_ilocked(node);
|
|
|
|
return node;
|
|
|
|
}
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
2017-06-12 12:07:26 -07:00
|
|
|
node = new_node;
|
2011-11-30 20:18:14 +09:00
|
|
|
binder_stats_created(BINDER_STAT_NODE);
|
2017-05-09 11:08:05 -07:00
|
|
|
node->tmp_refs++;
|
2011-11-30 20:18:14 +09:00
|
|
|
rb_link_node(&node->rb_node, parent, p);
|
|
|
|
rb_insert_color(&node->rb_node, &proc->nodes);
|
2016-09-30 16:40:04 +02:00
|
|
|
node->debug_id = atomic_inc_return(&binder_last_id);
|
2011-11-30 20:18:14 +09:00
|
|
|
node->proc = proc;
|
|
|
|
node->ptr = ptr;
|
|
|
|
node->cookie = cookie;
|
|
|
|
node->work.type = BINDER_WORK_NODE;
|
2017-06-07 09:29:14 -07:00
|
|
|
priority = flags & FLAT_BINDER_FLAG_PRIORITY_MASK;
|
2017-09-26 17:56:25 +08:00
|
|
|
node->sched_policy = (flags & FLAT_BINDER_FLAG_SCHED_POLICY_MASK) >>
|
2017-06-07 09:29:14 -07:00
|
|
|
FLAT_BINDER_FLAG_SCHED_POLICY_SHIFT;
|
|
|
|
node->min_priority = to_kernel_prio(node->sched_policy, priority);
|
2017-06-08 13:45:59 -07:00
|
|
|
node->accept_fds = !!(flags & FLAT_BINDER_FLAG_ACCEPTS_FDS);
|
2017-06-23 10:13:43 -07:00
|
|
|
node->inherit_rt = !!(flags & FLAT_BINDER_FLAG_INHERIT_RT);
|
2017-05-29 16:44:24 -07:00
|
|
|
spin_lock_init(&node->lock);
|
2011-11-30 20:18:14 +09:00
|
|
|
INIT_LIST_HEAD(&node->work.entry);
|
|
|
|
INIT_LIST_HEAD(&node->async_todo);
|
|
|
|
binder_debug(BINDER_DEBUG_INTERNAL_REFS,
|
2014-02-21 14:40:26 -08:00
|
|
|
"%d:%d node %d u%016llx c%016llx created\n",
|
2011-11-30 20:18:14 +09:00
|
|
|
proc->pid, current->pid, node->debug_id,
|
2014-02-21 14:40:26 -08:00
|
|
|
(u64)node->ptr, (u64)node->cookie);
|
2017-06-12 12:07:26 -07:00
|
|
|
|
2011-11-30 20:18:14 +09:00
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2017-06-12 12:07:26 -07:00
|
|
|
static struct binder_node *binder_new_node(struct binder_proc *proc,
|
|
|
|
struct flat_binder_object *fp)
|
|
|
|
{
|
|
|
|
struct binder_node *node;
|
|
|
|
struct binder_node *new_node = kzalloc(sizeof(*node), GFP_KERNEL);
|
|
|
|
|
|
|
|
if (!new_node)
|
|
|
|
return NULL;
|
|
|
|
binder_inner_proc_lock(proc);
|
|
|
|
node = binder_init_node_ilocked(proc, new_node, fp);
|
|
|
|
binder_inner_proc_unlock(proc);
|
|
|
|
if (node != new_node)
|
|
|
|
/*
|
|
|
|
* The node was already added by another thread
|
|
|
|
*/
|
|
|
|
kfree(new_node);
|
|
|
|
|
2011-11-30 20:18:14 +09:00
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2017-03-21 13:06:01 -07:00
|
|
|
static void binder_free_node(struct binder_node *node)
|
2011-11-30 20:18:14 +09:00
|
|
|
{
|
2017-03-21 13:06:01 -07:00
|
|
|
kfree(node);
|
|
|
|
binder_stats_deleted(BINDER_STAT_NODE);
|
|
|
|
}
|
|
|
|
|
2017-06-08 13:45:59 -07:00
|
|
|
static int binder_inc_node_nilocked(struct binder_node *node, int strong,
|
|
|
|
int internal,
|
|
|
|
struct list_head *target_list)
|
2017-03-21 13:06:01 -07:00
|
|
|
{
|
2017-06-08 13:45:59 -07:00
|
|
|
struct binder_proc *proc = node->proc;
|
|
|
|
|
2017-07-27 23:52:24 +02:00
|
|
|
assert_spin_locked(&node->lock);
|
2017-06-08 13:45:59 -07:00
|
|
|
if (proc)
|
2017-07-27 23:52:24 +02:00
|
|
|
assert_spin_locked(&proc->inner_lock);
|
2011-11-30 20:18:14 +09:00
|
|
|
if (strong) {
|
|
|
|
if (internal) {
|
|
|
|
if (target_list == NULL &&
|
|
|
|
node->internal_strong_refs == 0 &&
|
2016-09-30 15:51:48 +02:00
|
|
|
!(node->proc &&
|
|
|
|
node == node->proc->context->
|
|
|
|
binder_context_mgr_node &&
|
|
|
|
node->has_strong_ref)) {
|
2012-10-30 22:35:43 +05:30
|
|
|
pr_err("invalid inc strong node for %d\n",
|
|
|
|
node->debug_id);
|
2011-11-30 20:18:14 +09:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
node->internal_strong_refs++;
|
|
|
|
} else
|
|
|
|
node->local_strong_refs++;
|
|
|
|
if (!node->has_strong_ref && target_list) {
|
2016-10-20 10:33:00 -07:00
|
|
|
binder_dequeue_work_ilocked(&node->work);
|
2017-10-19 15:04:46 +02:00
|
|
|
/*
|
|
|
|
* Note: this function is the only place where we queue
|
|
|
|
* directly to a thread->todo without using the
|
|
|
|
* corresponding binder_enqueue_thread_work() helper
|
|
|
|
* functions; in this case it's ok to not set the
|
|
|
|
* process_todo flag, since we know this node work will
|
|
|
|
* always be followed by other work that starts queue
|
|
|
|
* processing: in case of synchronous transactions, a
|
|
|
|
* BR_REPLY or BR_ERROR; in case of oneway
|
|
|
|
* transactions, a BR_TRANSACTION_COMPLETE.
|
|
|
|
*/
|
2016-10-20 10:33:00 -07:00
|
|
|
binder_enqueue_work_ilocked(&node->work, target_list);
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!internal)
|
|
|
|
node->local_weak_refs++;
|
|
|
|
if (!node->has_weak_ref && list_empty(&node->work.entry)) {
|
|
|
|
if (target_list == NULL) {
|
2012-10-30 22:35:43 +05:30
|
|
|
pr_err("invalid inc weak node for %d\n",
|
|
|
|
node->debug_id);
|
2011-11-30 20:18:14 +09:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
2017-10-19 15:04:46 +02:00
|
|
|
/*
|
|
|
|
* See comment above
|
|
|
|
*/
|
2016-10-20 10:33:00 -07:00
|
|
|
binder_enqueue_work_ilocked(&node->work, target_list);
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-03-21 13:06:01 -07:00
|
|
|
static int binder_inc_node(struct binder_node *node, int strong, int internal,
|
|
|
|
struct list_head *target_list)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2017-06-08 13:45:59 -07:00
|
|
|
binder_node_inner_lock(node);
|
|
|
|
ret = binder_inc_node_nilocked(node, strong, internal, target_list);
|
|
|
|
binder_node_inner_unlock(node);
|
2017-03-21 13:06:01 -07:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-06-08 13:45:59 -07:00
|
|
|
static bool binder_dec_node_nilocked(struct binder_node *node,
|
|
|
|
int strong, int internal)
|
2011-11-30 20:18:14 +09:00
|
|
|
{
|
2017-03-21 13:06:01 -07:00
|
|
|
struct binder_proc *proc = node->proc;
|
|
|
|
|
2017-07-27 23:52:24 +02:00
|
|
|
assert_spin_locked(&node->lock);
|
2017-03-21 13:06:01 -07:00
|
|
|
if (proc)
|
2017-07-27 23:52:24 +02:00
|
|
|
assert_spin_locked(&proc->inner_lock);
|
2011-11-30 20:18:14 +09:00
|
|
|
if (strong) {
|
|
|
|
if (internal)
|
|
|
|
node->internal_strong_refs--;
|
|
|
|
else
|
|
|
|
node->local_strong_refs--;
|
|
|
|
if (node->local_strong_refs || node->internal_strong_refs)
|
2017-03-21 13:06:01 -07:00
|
|
|
return false;
|
2011-11-30 20:18:14 +09:00
|
|
|
} else {
|
|
|
|
if (!internal)
|
|
|
|
node->local_weak_refs--;
|
2017-05-09 11:08:05 -07:00
|
|
|
if (node->local_weak_refs || node->tmp_refs ||
|
|
|
|
!hlist_empty(&node->refs))
|
2017-03-21 13:06:01 -07:00
|
|
|
return false;
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
2017-03-21 13:06:01 -07:00
|
|
|
|
|
|
|
if (proc && (node->has_strong_ref || node->has_weak_ref)) {
|
2011-11-30 20:18:14 +09:00
|
|
|
if (list_empty(&node->work.entry)) {
|
2016-10-20 10:33:00 -07:00
|
|
|
binder_enqueue_work_ilocked(&node->work, &proc->todo);
|
2017-06-06 15:17:46 -07:00
|
|
|
binder_wakeup_proc_ilocked(proc);
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (hlist_empty(&node->refs) && !node->local_strong_refs &&
|
2017-05-09 11:08:05 -07:00
|
|
|
!node->local_weak_refs && !node->tmp_refs) {
|
2017-03-21 13:06:01 -07:00
|
|
|
if (proc) {
|
2016-10-20 10:33:00 -07:00
|
|
|
binder_dequeue_work_ilocked(&node->work);
|
|
|
|
rb_erase(&node->rb_node, &proc->nodes);
|
2011-11-30 20:18:14 +09:00
|
|
|
binder_debug(BINDER_DEBUG_INTERNAL_REFS,
|
2012-10-30 22:35:43 +05:30
|
|
|
"refless node %d deleted\n",
|
2011-11-30 20:18:14 +09:00
|
|
|
node->debug_id);
|
|
|
|
} else {
|
2016-10-20 10:33:00 -07:00
|
|
|
BUG_ON(!list_empty(&node->work.entry));
|
2016-10-17 12:33:15 -07:00
|
|
|
spin_lock(&binder_dead_nodes_lock);
|
2017-03-21 13:06:01 -07:00
|
|
|
/*
|
|
|
|
* tmp_refs could have changed so
|
|
|
|
* check it again
|
|
|
|
*/
|
|
|
|
if (node->tmp_refs) {
|
|
|
|
spin_unlock(&binder_dead_nodes_lock);
|
|
|
|
return false;
|
|
|
|
}
|
2011-11-30 20:18:14 +09:00
|
|
|
hlist_del(&node->dead_node);
|
2016-10-17 12:33:15 -07:00
|
|
|
spin_unlock(&binder_dead_nodes_lock);
|
2011-11-30 20:18:14 +09:00
|
|
|
binder_debug(BINDER_DEBUG_INTERNAL_REFS,
|
2012-10-30 22:35:43 +05:30
|
|
|
"dead node %d deleted\n",
|
2011-11-30 20:18:14 +09:00
|
|
|
node->debug_id);
|
|
|
|
}
|
2017-03-21 13:06:01 -07:00
|
|
|
return true;
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
|
|
|
}
|
2017-03-21 13:06:01 -07:00
|
|
|
return false;
|
|
|
|
}
|
2011-11-30 20:18:14 +09:00
|
|
|
|
2017-03-21 13:06:01 -07:00
|
|
|
static void binder_dec_node(struct binder_node *node, int strong, int internal)
|
|
|
|
{
|
|
|
|
bool free_node;
|
|
|
|
|
2017-06-08 13:45:59 -07:00
|
|
|
binder_node_inner_lock(node);
|
|
|
|
free_node = binder_dec_node_nilocked(node, strong, internal);
|
|
|
|
binder_node_inner_unlock(node);
|
2017-03-21 13:06:01 -07:00
|
|
|
if (free_node)
|
|
|
|
binder_free_node(node);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void binder_inc_node_tmpref_ilocked(struct binder_node *node)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* No call to binder_inc_node() is needed since we
|
|
|
|
* don't need to inform userspace of any changes to
|
|
|
|
* tmp_refs
|
|
|
|
*/
|
|
|
|
node->tmp_refs++;
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
|
|
|
|
2017-05-09 11:08:05 -07:00
|
|
|
/**
|
|
|
|
* binder_inc_node_tmpref() - take a temporary reference on node
|
|
|
|
* @node: node to reference
|
|
|
|
*
|
|
|
|
* Take reference on node to prevent the node from being freed
|
2017-03-21 13:06:01 -07:00
|
|
|
* while referenced only by a local variable. The inner lock is
|
|
|
|
* needed to serialize with the node work on the queue (which
|
|
|
|
* isn't needed after the node is dead). If the node is dead
|
|
|
|
* (node->proc is NULL), use binder_dead_nodes_lock to protect
|
|
|
|
* node->tmp_refs against dead-node-only cases where the node
|
|
|
|
* lock cannot be acquired (eg traversing the dead node list to
|
|
|
|
* print nodes)
|
2017-05-09 11:08:05 -07:00
|
|
|
*/
|
|
|
|
static void binder_inc_node_tmpref(struct binder_node *node)
|
|
|
|
{
|
2017-06-08 13:45:59 -07:00
|
|
|
binder_node_lock(node);
|
2017-03-21 13:06:01 -07:00
|
|
|
if (node->proc)
|
|
|
|
binder_inner_proc_lock(node->proc);
|
|
|
|
else
|
|
|
|
spin_lock(&binder_dead_nodes_lock);
|
|
|
|
binder_inc_node_tmpref_ilocked(node);
|
|
|
|
if (node->proc)
|
|
|
|
binder_inner_proc_unlock(node->proc);
|
|
|
|
else
|
|
|
|
spin_unlock(&binder_dead_nodes_lock);
|
2017-06-08 13:45:59 -07:00
|
|
|
binder_node_unlock(node);
|
2017-05-09 11:08:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* binder_dec_node_tmpref() - remove a temporary reference on node
|
|
|
|
* @node: node to reference
|
|
|
|
*
|
|
|
|
* Release temporary reference on node taken via binder_inc_node_tmpref()
|
|
|
|
*/
|
|
|
|
static void binder_dec_node_tmpref(struct binder_node *node)
|
|
|
|
{
|
2017-03-21 13:06:01 -07:00
|
|
|
bool free_node;
|
|
|
|
|
2017-06-08 13:45:59 -07:00
|
|
|
binder_node_inner_lock(node);
|
|
|
|
if (!node->proc)
|
2017-03-21 13:06:01 -07:00
|
|
|
spin_lock(&binder_dead_nodes_lock);
|
2017-05-09 11:08:05 -07:00
|
|
|
node->tmp_refs--;
|
|
|
|
BUG_ON(node->tmp_refs < 0);
|
2017-03-21 13:06:01 -07:00
|
|
|
if (!node->proc)
|
|
|
|
spin_unlock(&binder_dead_nodes_lock);
|
2017-05-09 11:08:05 -07:00
|
|
|
/*
|
|
|
|
* Call binder_dec_node() to check if all refcounts are 0
|
|
|
|
* and cleanup is needed. Calling with strong=0 and internal=1
|
|
|
|
* causes no actual reference to be released in binder_dec_node().
|
|
|
|
* If that changes, a change is needed here too.
|
|
|
|
*/
|
2017-06-08 13:45:59 -07:00
|
|
|
free_node = binder_dec_node_nilocked(node, 0, 1);
|
|
|
|
binder_node_inner_unlock(node);
|
2017-03-21 13:06:01 -07:00
|
|
|
if (free_node)
|
|
|
|
binder_free_node(node);
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
|
|
|
|
2017-05-09 11:08:05 -07:00
|
|
|
static void binder_put_node(struct binder_node *node)
|
|
|
|
{
|
|
|
|
binder_dec_node_tmpref(node);
|
|
|
|
}
|
2011-11-30 20:18:14 +09:00
|
|
|
|
2016-10-20 16:43:34 -07:00
|
|
|
static struct binder_ref *binder_get_ref_olocked(struct binder_proc *proc,
|
|
|
|
u32 desc, bool need_strong_ref)
|
2011-11-30 20:18:14 +09:00
|
|
|
{
|
|
|
|
struct rb_node *n = proc->refs_by_desc.rb_node;
|
|
|
|
struct binder_ref *ref;
|
|
|
|
|
|
|
|
while (n) {
|
|
|
|
ref = rb_entry(n, struct binder_ref, rb_node_desc);
|
|
|
|
|
2017-05-08 09:16:27 -07:00
|
|
|
if (desc < ref->data.desc) {
|
2011-11-30 20:18:14 +09:00
|
|
|
n = n->rb_left;
|
2017-05-08 09:16:27 -07:00
|
|
|
} else if (desc > ref->data.desc) {
|
2011-11-30 20:18:14 +09:00
|
|
|
n = n->rb_right;
|
2017-05-08 09:16:27 -07:00
|
|
|
} else if (need_strong_ref && !ref->data.strong) {
|
2016-08-02 15:40:39 -07:00
|
|
|
binder_user_error("tried to use weak ref as strong ref\n");
|
|
|
|
return NULL;
|
|
|
|
} else {
|
2011-11-30 20:18:14 +09:00
|
|
|
return ref;
|
2016-08-02 15:40:39 -07:00
|
|
|
}
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-05-08 09:16:27 -07:00
|
|
|
/**
|
2016-10-20 16:43:34 -07:00
|
|
|
* binder_get_ref_for_node_olocked() - get the ref associated with given node
|
2017-05-08 09:16:27 -07:00
|
|
|
* @proc: binder_proc that owns the ref
|
|
|
|
* @node: binder_node of target
|
|
|
|
* @new_ref: newly allocated binder_ref to be initialized or %NULL
|
|
|
|
*
|
|
|
|
* Look up the ref for the given node and return it if it exists
|
|
|
|
*
|
|
|
|
* If it doesn't exist and the caller provides a newly allocated
|
|
|
|
* ref, initialize the fields of the newly allocated ref and insert
|
|
|
|
* into the given proc rb_trees and node refs list.
|
|
|
|
*
|
|
|
|
* Return: the ref for node. It is possible that another thread
|
|
|
|
* allocated/initialized the ref first in which case the
|
|
|
|
* returned ref would be different than the passed-in
|
|
|
|
* new_ref. new_ref must be kfree'd by the caller in
|
|
|
|
* this case.
|
|
|
|
*/
|
2016-10-20 16:43:34 -07:00
|
|
|
static struct binder_ref *binder_get_ref_for_node_olocked(
|
|
|
|
struct binder_proc *proc,
|
|
|
|
struct binder_node *node,
|
|
|
|
struct binder_ref *new_ref)
|
2011-11-30 20:18:14 +09:00
|
|
|
{
|
2017-05-08 09:16:27 -07:00
|
|
|
struct binder_context *context = proc->context;
|
2011-11-30 20:18:14 +09:00
|
|
|
struct rb_node **p = &proc->refs_by_node.rb_node;
|
|
|
|
struct rb_node *parent = NULL;
|
2017-05-08 09:16:27 -07:00
|
|
|
struct binder_ref *ref;
|
|
|
|
struct rb_node *n;
|
2011-11-30 20:18:14 +09:00
|
|
|
|
|
|
|
while (*p) {
|
|
|
|
parent = *p;
|
|
|
|
ref = rb_entry(parent, struct binder_ref, rb_node_node);
|
|
|
|
|
|
|
|
if (node < ref->node)
|
|
|
|
p = &(*p)->rb_left;
|
|
|
|
else if (node > ref->node)
|
|
|
|
p = &(*p)->rb_right;
|
|
|
|
else
|
|
|
|
return ref;
|
|
|
|
}
|
2017-05-08 09:16:27 -07:00
|
|
|
if (!new_ref)
|
2011-11-30 20:18:14 +09:00
|
|
|
return NULL;
|
2017-05-08 09:16:27 -07:00
|
|
|
|
2011-11-30 20:18:14 +09:00
|
|
|
binder_stats_created(BINDER_STAT_REF);
|
2017-05-08 09:16:27 -07:00
|
|
|
new_ref->data.debug_id = atomic_inc_return(&binder_last_id);
|
2011-11-30 20:18:14 +09:00
|
|
|
new_ref->proc = proc;
|
|
|
|
new_ref->node = node;
|
|
|
|
rb_link_node(&new_ref->rb_node_node, parent, p);
|
|
|
|
rb_insert_color(&new_ref->rb_node_node, &proc->refs_by_node);
|
|
|
|
|
2017-05-08 09:16:27 -07:00
|
|
|
new_ref->data.desc = (node == context->binder_context_mgr_node) ? 0 : 1;
|
2011-11-30 20:18:14 +09:00
|
|
|
for (n = rb_first(&proc->refs_by_desc); n != NULL; n = rb_next(n)) {
|
|
|
|
ref = rb_entry(n, struct binder_ref, rb_node_desc);
|
2017-05-08 09:16:27 -07:00
|
|
|
if (ref->data.desc > new_ref->data.desc)
|
2011-11-30 20:18:14 +09:00
|
|
|
break;
|
2017-05-08 09:16:27 -07:00
|
|
|
new_ref->data.desc = ref->data.desc + 1;
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
p = &proc->refs_by_desc.rb_node;
|
|
|
|
while (*p) {
|
|
|
|
parent = *p;
|
|
|
|
ref = rb_entry(parent, struct binder_ref, rb_node_desc);
|
|
|
|
|
2017-05-08 09:16:27 -07:00
|
|
|
if (new_ref->data.desc < ref->data.desc)
|
2011-11-30 20:18:14 +09:00
|
|
|
p = &(*p)->rb_left;
|
2017-05-08 09:16:27 -07:00
|
|
|
else if (new_ref->data.desc > ref->data.desc)
|
2011-11-30 20:18:14 +09:00
|
|
|
p = &(*p)->rb_right;
|
|
|
|
else
|
|
|
|
BUG();
|
|
|
|
}
|
|
|
|
rb_link_node(&new_ref->rb_node_desc, parent, p);
|
|
|
|
rb_insert_color(&new_ref->rb_node_desc, &proc->refs_by_desc);
|
|
|
|
|
2017-06-08 13:45:59 -07:00
|
|
|
binder_node_lock(node);
|
2017-05-01 17:21:51 -07:00
|
|
|
hlist_add_head(&new_ref->node_entry, &node->refs);
|
2011-11-30 20:18:14 +09:00
|
|
|
|
2017-05-01 17:21:51 -07:00
|
|
|
binder_debug(BINDER_DEBUG_INTERNAL_REFS,
|
|
|
|
"%d new ref %d desc %d for node %d\n",
|
2017-05-08 09:16:27 -07:00
|
|
|
proc->pid, new_ref->data.debug_id, new_ref->data.desc,
|
2017-05-01 17:21:51 -07:00
|
|
|
node->debug_id);
|
2017-06-08 13:45:59 -07:00
|
|
|
binder_node_unlock(node);
|
2011-11-30 20:18:14 +09:00
|
|
|
return new_ref;
|
|
|
|
}
|
|
|
|
|
2016-10-20 16:43:34 -07:00
|
|
|
static void binder_cleanup_ref_olocked(struct binder_ref *ref)
|
2011-11-30 20:18:14 +09:00
|
|
|
{
|
2017-03-21 13:06:01 -07:00
|
|
|
bool delete_node = false;
|
|
|
|
|
2011-11-30 20:18:14 +09:00
|
|
|
binder_debug(BINDER_DEBUG_INTERNAL_REFS,
|
2012-10-30 22:35:43 +05:30
|
|
|
"%d delete ref %d desc %d for node %d\n",
|
2017-05-08 09:16:27 -07:00
|
|
|
ref->proc->pid, ref->data.debug_id, ref->data.desc,
|
2012-10-30 22:35:43 +05:30
|
|
|
ref->node->debug_id);
|
2011-11-30 20:18:14 +09:00
|
|
|
|
|
|
|
rb_erase(&ref->rb_node_desc, &ref->proc->refs_by_desc);
|
|
|
|
rb_erase(&ref->rb_node_node, &ref->proc->refs_by_node);
|
2017-05-08 09:16:27 -07:00
|
|
|
|
2017-06-08 13:45:59 -07:00
|
|
|
binder_node_inner_lock(ref->node);
|
2017-05-08 09:16:27 -07:00
|
|
|
if (ref->data.strong)
|
2017-06-08 13:45:59 -07:00
|
|
|
binder_dec_node_nilocked(ref->node, 1, 1);
|
2017-05-08 09:16:27 -07:00
|
|
|
|
2011-11-30 20:18:14 +09:00
|
|
|
hlist_del(&ref->node_entry);
|
2017-06-08 13:45:59 -07:00
|
|
|
delete_node = binder_dec_node_nilocked(ref->node, 0, 1);
|
|
|
|
binder_node_inner_unlock(ref->node);
|
2017-03-21 13:06:01 -07:00
|
|
|
/*
|
|
|
|
* Clear ref->node unless we want the caller to free the node
|
|
|
|
*/
|
|
|
|
if (!delete_node) {
|
|
|
|
/*
|
|
|
|
* The caller uses ref->node to determine
|
|
|
|
* whether the node needs to be freed. Clear
|
|
|
|
* it since the node is still alive.
|
|
|
|
*/
|
|
|
|
ref->node = NULL;
|
|
|
|
}
|
2017-05-08 09:16:27 -07:00
|
|
|
|
2011-11-30 20:18:14 +09:00
|
|
|
if (ref->death) {
|
|
|
|
binder_debug(BINDER_DEBUG_DEAD_BINDER,
|
2012-10-30 22:35:43 +05:30
|
|
|
"%d delete ref %d desc %d has death notification\n",
|
2017-05-08 09:16:27 -07:00
|
|
|
ref->proc->pid, ref->data.debug_id,
|
|
|
|
ref->data.desc);
|
2016-10-20 10:33:00 -07:00
|
|
|
binder_dequeue_work(ref->proc, &ref->death->work);
|
2011-11-30 20:18:14 +09:00
|
|
|
binder_stats_deleted(BINDER_STAT_DEATH);
|
|
|
|
}
|
|
|
|
binder_stats_deleted(BINDER_STAT_REF);
|
|
|
|
}
|
|
|
|
|
2017-05-08 09:16:27 -07:00
|
|
|
/**
|
2016-10-20 16:43:34 -07:00
|
|
|
* binder_inc_ref_olocked() - increment the ref for given handle
|
2017-05-08 09:16:27 -07:00
|
|
|
* @ref: ref to be incremented
|
|
|
|
* @strong: if true, strong increment, else weak
|
|
|
|
* @target_list: list to queue node work on
|
|
|
|
*
|
2016-10-20 16:43:34 -07:00
|
|
|
* Increment the ref. @ref->proc->outer_lock must be held on entry
|
2017-05-08 09:16:27 -07:00
|
|
|
*
|
|
|
|
* Return: 0, if successful, else errno
|
|
|
|
*/
|
2016-10-20 16:43:34 -07:00
|
|
|
static int binder_inc_ref_olocked(struct binder_ref *ref, int strong,
|
|
|
|
struct list_head *target_list)
|
2011-11-30 20:18:14 +09:00
|
|
|
{
|
|
|
|
int ret;
|
2014-05-01 01:30:23 +09:00
|
|
|
|
2011-11-30 20:18:14 +09:00
|
|
|
if (strong) {
|
2017-05-08 09:16:27 -07:00
|
|
|
if (ref->data.strong == 0) {
|
2011-11-30 20:18:14 +09:00
|
|
|
ret = binder_inc_node(ref->node, 1, 1, target_list);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
2017-05-08 09:16:27 -07:00
|
|
|
ref->data.strong++;
|
2011-11-30 20:18:14 +09:00
|
|
|
} else {
|
2017-05-08 09:16:27 -07:00
|
|
|
if (ref->data.weak == 0) {
|
2011-11-30 20:18:14 +09:00
|
|
|
ret = binder_inc_node(ref->node, 0, 1, target_list);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
2017-05-08 09:16:27 -07:00
|
|
|
ref->data.weak++;
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-05-08 09:16:27 -07:00
|
|
|
/**
|
|
|
|
* binder_dec_ref() - dec the ref for given handle
|
|
|
|
* @ref: ref to be decremented
|
|
|
|
* @strong: if true, strong decrement, else weak
|
|
|
|
*
|
|
|
|
* Decrement the ref.
|
|
|
|
*
|
|
|
|
* Return: true if ref is cleaned up and ready to be freed
|
|
|
|
*/
|
2016-10-20 16:43:34 -07:00
|
|
|
static bool binder_dec_ref_olocked(struct binder_ref *ref, int strong)
|
2011-11-30 20:18:14 +09:00
|
|
|
{
|
|
|
|
if (strong) {
|
2017-05-08 09:16:27 -07:00
|
|
|
if (ref->data.strong == 0) {
|
2012-10-30 22:35:43 +05:30
|
|
|
binder_user_error("%d invalid dec strong, ref %d desc %d s %d w %d\n",
|
2017-05-08 09:16:27 -07:00
|
|
|
ref->proc->pid, ref->data.debug_id,
|
|
|
|
ref->data.desc, ref->data.strong,
|
|
|
|
ref->data.weak);
|
|
|
|
return false;
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
2017-05-08 09:16:27 -07:00
|
|
|
ref->data.strong--;
|
2017-03-21 13:06:01 -07:00
|
|
|
if (ref->data.strong == 0)
|
|
|
|
binder_dec_node(ref->node, strong, 1);
|
2011-11-30 20:18:14 +09:00
|
|
|
} else {
|
2017-05-08 09:16:27 -07:00
|
|
|
if (ref->data.weak == 0) {
|
2012-10-30 22:35:43 +05:30
|
|
|
binder_user_error("%d invalid dec weak, ref %d desc %d s %d w %d\n",
|
2017-05-08 09:16:27 -07:00
|
|
|
ref->proc->pid, ref->data.debug_id,
|
|
|
|
ref->data.desc, ref->data.strong,
|
|
|
|
ref->data.weak);
|
|
|
|
return false;
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
2017-05-08 09:16:27 -07:00
|
|
|
ref->data.weak--;
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
2017-05-08 09:16:27 -07:00
|
|
|
if (ref->data.strong == 0 && ref->data.weak == 0) {
|
2016-10-20 16:43:34 -07:00
|
|
|
binder_cleanup_ref_olocked(ref);
|
2017-05-08 09:16:27 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* binder_get_node_from_ref() - get the node from the given proc/desc
|
|
|
|
* @proc: proc containing the ref
|
|
|
|
* @desc: the handle associated with the ref
|
|
|
|
* @need_strong_ref: if true, only return node if ref is strong
|
|
|
|
* @rdata: the id/refcount data for the ref
|
|
|
|
*
|
|
|
|
* Given a proc and ref handle, return the associated binder_node
|
|
|
|
*
|
|
|
|
* Return: a binder_node or NULL if not found or not strong when strong required
|
|
|
|
*/
|
|
|
|
static struct binder_node *binder_get_node_from_ref(
|
|
|
|
struct binder_proc *proc,
|
|
|
|
u32 desc, bool need_strong_ref,
|
|
|
|
struct binder_ref_data *rdata)
|
|
|
|
{
|
|
|
|
struct binder_node *node;
|
|
|
|
struct binder_ref *ref;
|
|
|
|
|
2016-10-20 16:43:34 -07:00
|
|
|
binder_proc_lock(proc);
|
|
|
|
ref = binder_get_ref_olocked(proc, desc, need_strong_ref);
|
2017-05-08 09:16:27 -07:00
|
|
|
if (!ref)
|
|
|
|
goto err_no_ref;
|
|
|
|
node = ref->node;
|
2017-05-09 11:08:05 -07:00
|
|
|
/*
|
|
|
|
* Take an implicit reference on the node to ensure
|
|
|
|
* it stays alive until the call to binder_put_node()
|
|
|
|
*/
|
|
|
|
binder_inc_node_tmpref(node);
|
2017-05-08 09:16:27 -07:00
|
|
|
if (rdata)
|
|
|
|
*rdata = ref->data;
|
2016-10-20 16:43:34 -07:00
|
|
|
binder_proc_unlock(proc);
|
2017-05-08 09:16:27 -07:00
|
|
|
|
|
|
|
return node;
|
|
|
|
|
|
|
|
err_no_ref:
|
2016-10-20 16:43:34 -07:00
|
|
|
binder_proc_unlock(proc);
|
2017-05-08 09:16:27 -07:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* binder_free_ref() - free the binder_ref
|
|
|
|
* @ref: ref to free
|
|
|
|
*
|
2017-03-21 13:06:01 -07:00
|
|
|
* Free the binder_ref. Free the binder_node indicated by ref->node
|
|
|
|
* (if non-NULL) and the binder_ref_death indicated by ref->death.
|
2017-05-08 09:16:27 -07:00
|
|
|
*/
|
|
|
|
static void binder_free_ref(struct binder_ref *ref)
|
|
|
|
{
|
2017-03-21 13:06:01 -07:00
|
|
|
if (ref->node)
|
|
|
|
binder_free_node(ref->node);
|
2017-05-08 09:16:27 -07:00
|
|
|
kfree(ref->death);
|
|
|
|
kfree(ref);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* binder_update_ref_for_handle() - inc/dec the ref for given handle
|
|
|
|
* @proc: proc containing the ref
|
|
|
|
* @desc: the handle associated with the ref
|
|
|
|
* @increment: true=inc reference, false=dec reference
|
|
|
|
* @strong: true=strong reference, false=weak reference
|
|
|
|
* @rdata: the id/refcount data for the ref
|
|
|
|
*
|
|
|
|
* Given a proc and ref handle, increment or decrement the ref
|
|
|
|
* according to "increment" arg.
|
|
|
|
*
|
|
|
|
* Return: 0 if successful, else errno
|
|
|
|
*/
|
|
|
|
static int binder_update_ref_for_handle(struct binder_proc *proc,
|
|
|
|
uint32_t desc, bool increment, bool strong,
|
|
|
|
struct binder_ref_data *rdata)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
struct binder_ref *ref;
|
|
|
|
bool delete_ref = false;
|
|
|
|
|
2016-10-20 16:43:34 -07:00
|
|
|
binder_proc_lock(proc);
|
|
|
|
ref = binder_get_ref_olocked(proc, desc, strong);
|
2017-05-08 09:16:27 -07:00
|
|
|
if (!ref) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto err_no_ref;
|
|
|
|
}
|
|
|
|
if (increment)
|
2016-10-20 16:43:34 -07:00
|
|
|
ret = binder_inc_ref_olocked(ref, strong, NULL);
|
2017-05-08 09:16:27 -07:00
|
|
|
else
|
2016-10-20 16:43:34 -07:00
|
|
|
delete_ref = binder_dec_ref_olocked(ref, strong);
|
2017-05-08 09:16:27 -07:00
|
|
|
|
|
|
|
if (rdata)
|
|
|
|
*rdata = ref->data;
|
2016-10-20 16:43:34 -07:00
|
|
|
binder_proc_unlock(proc);
|
2017-05-08 09:16:27 -07:00
|
|
|
|
|
|
|
if (delete_ref)
|
|
|
|
binder_free_ref(ref);
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
err_no_ref:
|
2016-10-20 16:43:34 -07:00
|
|
|
binder_proc_unlock(proc);
|
2017-05-08 09:16:27 -07:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* binder_dec_ref_for_handle() - dec the ref for given handle
|
|
|
|
* @proc: proc containing the ref
|
|
|
|
* @desc: the handle associated with the ref
|
|
|
|
* @strong: true=strong reference, false=weak reference
|
|
|
|
* @rdata: the id/refcount data for the ref
|
|
|
|
*
|
|
|
|
* Just calls binder_update_ref_for_handle() to decrement the ref.
|
|
|
|
*
|
|
|
|
* Return: 0 if successful, else errno
|
|
|
|
*/
|
|
|
|
static int binder_dec_ref_for_handle(struct binder_proc *proc,
|
|
|
|
uint32_t desc, bool strong, struct binder_ref_data *rdata)
|
|
|
|
{
|
|
|
|
return binder_update_ref_for_handle(proc, desc, false, strong, rdata);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* binder_inc_ref_for_node() - increment the ref for given proc/node
|
|
|
|
* @proc: proc containing the ref
|
|
|
|
* @node: target node
|
|
|
|
* @strong: true=strong reference, false=weak reference
|
|
|
|
* @target_list: worklist to use if node is incremented
|
|
|
|
* @rdata: the id/refcount data for the ref
|
|
|
|
*
|
|
|
|
* Given a proc and node, increment the ref. Create the ref if it
|
|
|
|
* doesn't already exist
|
|
|
|
*
|
|
|
|
* Return: 0 if successful, else errno
|
|
|
|
*/
|
|
|
|
static int binder_inc_ref_for_node(struct binder_proc *proc,
|
|
|
|
struct binder_node *node,
|
|
|
|
bool strong,
|
|
|
|
struct list_head *target_list,
|
|
|
|
struct binder_ref_data *rdata)
|
|
|
|
{
|
|
|
|
struct binder_ref *ref;
|
|
|
|
struct binder_ref *new_ref = NULL;
|
|
|
|
int ret = 0;
|
|
|
|
|
2016-10-20 16:43:34 -07:00
|
|
|
binder_proc_lock(proc);
|
|
|
|
ref = binder_get_ref_for_node_olocked(proc, node, NULL);
|
2017-05-08 09:16:27 -07:00
|
|
|
if (!ref) {
|
2016-10-20 16:43:34 -07:00
|
|
|
binder_proc_unlock(proc);
|
2017-05-08 09:16:27 -07:00
|
|
|
new_ref = kzalloc(sizeof(*ref), GFP_KERNEL);
|
|
|
|
if (!new_ref)
|
|
|
|
return -ENOMEM;
|
2016-10-20 16:43:34 -07:00
|
|
|
binder_proc_lock(proc);
|
|
|
|
ref = binder_get_ref_for_node_olocked(proc, node, new_ref);
|
2017-05-08 09:16:27 -07:00
|
|
|
}
|
2016-10-20 16:43:34 -07:00
|
|
|
ret = binder_inc_ref_olocked(ref, strong, target_list);
|
2017-05-08 09:16:27 -07:00
|
|
|
*rdata = ref->data;
|
2016-10-20 16:43:34 -07:00
|
|
|
binder_proc_unlock(proc);
|
2017-05-08 09:16:27 -07:00
|
|
|
if (new_ref && ref != new_ref)
|
|
|
|
/*
|
|
|
|
* Another thread created the ref first so
|
|
|
|
* free the one we allocated
|
|
|
|
*/
|
|
|
|
kfree(new_ref);
|
|
|
|
return ret;
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
|
|
|
|
2017-06-02 13:36:52 -07:00
|
|
|
static void binder_pop_transaction_ilocked(struct binder_thread *target_thread,
|
|
|
|
struct binder_transaction *t)
|
2011-11-30 20:18:14 +09:00
|
|
|
{
|
2017-03-30 18:02:13 -07:00
|
|
|
BUG_ON(!target_thread);
|
2017-07-27 23:52:24 +02:00
|
|
|
assert_spin_locked(&target_thread->proc->inner_lock);
|
2017-03-30 18:02:13 -07:00
|
|
|
BUG_ON(target_thread->transaction_stack != t);
|
|
|
|
BUG_ON(target_thread->transaction_stack->from != target_thread);
|
|
|
|
target_thread->transaction_stack =
|
|
|
|
target_thread->transaction_stack->from_parent;
|
|
|
|
t->from = NULL;
|
|
|
|
}
|
|
|
|
|
2017-05-12 14:42:55 -07:00
|
|
|
/**
|
|
|
|
* binder_thread_dec_tmpref() - decrement thread->tmp_ref
|
|
|
|
* @thread: thread to decrement
|
|
|
|
*
|
|
|
|
* A thread needs to be kept alive while being used to create or
|
|
|
|
* handle a transaction. binder_get_txn_from() is used to safely
|
|
|
|
* extract t->from from a binder_transaction and keep the thread
|
|
|
|
* indicated by t->from from being freed. When done with that
|
|
|
|
* binder_thread, this function is called to decrement the
|
|
|
|
* tmp_ref and free if appropriate (thread has been released
|
|
|
|
* and no transaction being processed by the driver)
|
|
|
|
*/
|
|
|
|
static void binder_thread_dec_tmpref(struct binder_thread *thread)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* atomic is used to protect the counter value while
|
|
|
|
* it cannot reach zero or thread->is_dead is false
|
|
|
|
*/
|
2017-05-25 15:52:17 -07:00
|
|
|
binder_inner_proc_lock(thread->proc);
|
2017-05-12 14:42:55 -07:00
|
|
|
atomic_dec(&thread->tmp_ref);
|
|
|
|
if (thread->is_dead && !atomic_read(&thread->tmp_ref)) {
|
2017-05-25 15:52:17 -07:00
|
|
|
binder_inner_proc_unlock(thread->proc);
|
2017-05-12 14:42:55 -07:00
|
|
|
binder_free_thread(thread);
|
|
|
|
return;
|
|
|
|
}
|
2017-05-25 15:52:17 -07:00
|
|
|
binder_inner_proc_unlock(thread->proc);
|
2017-05-12 14:42:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* binder_proc_dec_tmpref() - decrement proc->tmp_ref
|
|
|
|
* @proc: proc to decrement
|
|
|
|
*
|
|
|
|
* A binder_proc needs to be kept alive while being used to create or
|
|
|
|
* handle a transaction. proc->tmp_ref is incremented when
|
|
|
|
* creating a new transaction or the binder_proc is currently in-use
|
|
|
|
* by threads that are being released. When done with the binder_proc,
|
|
|
|
* this function is called to decrement the counter and free the
|
|
|
|
* proc if appropriate (proc has been released, all threads have
|
|
|
|
* been released and not currenly in-use to process a transaction).
|
|
|
|
*/
|
|
|
|
static void binder_proc_dec_tmpref(struct binder_proc *proc)
|
|
|
|
{
|
2017-05-25 15:52:17 -07:00
|
|
|
binder_inner_proc_lock(proc);
|
2017-05-12 14:42:55 -07:00
|
|
|
proc->tmp_ref--;
|
|
|
|
if (proc->is_dead && RB_EMPTY_ROOT(&proc->threads) &&
|
|
|
|
!proc->tmp_ref) {
|
2017-05-25 15:52:17 -07:00
|
|
|
binder_inner_proc_unlock(proc);
|
2017-05-12 14:42:55 -07:00
|
|
|
binder_free_proc(proc);
|
|
|
|
return;
|
|
|
|
}
|
2017-05-25 15:52:17 -07:00
|
|
|
binder_inner_proc_unlock(proc);
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
|
|
|
|
2017-05-12 14:42:55 -07:00
|
|
|
/**
|
|
|
|
* binder_get_txn_from() - safely extract the "from" thread in transaction
|
|
|
|
* @t: binder transaction for t->from
|
|
|
|
*
|
|
|
|
* Atomically return the "from" thread and increment the tmp_ref
|
|
|
|
* count for the thread to ensure it stays alive until
|
|
|
|
* binder_thread_dec_tmpref() is called.
|
|
|
|
*
|
|
|
|
* Return: the value of t->from
|
|
|
|
*/
|
|
|
|
static struct binder_thread *binder_get_txn_from(
|
|
|
|
struct binder_transaction *t)
|
2011-11-30 20:18:14 +09:00
|
|
|
{
|
2017-05-12 14:42:55 -07:00
|
|
|
struct binder_thread *from;
|
2014-05-01 01:30:23 +09:00
|
|
|
|
2017-05-12 14:42:55 -07:00
|
|
|
spin_lock(&t->lock);
|
|
|
|
from = t->from;
|
|
|
|
if (from)
|
|
|
|
atomic_inc(&from->tmp_ref);
|
|
|
|
spin_unlock(&t->lock);
|
|
|
|
return from;
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
|
|
|
|
2017-06-02 13:36:52 -07:00
|
|
|
/**
|
|
|
|
* binder_get_txn_from_and_acq_inner() - get t->from and acquire inner lock
|
|
|
|
* @t: binder transaction for t->from
|
|
|
|
*
|
|
|
|
* Same as binder_get_txn_from() except it also acquires the proc->inner_lock
|
|
|
|
* to guarantee that the thread cannot be released while operating on it.
|
|
|
|
* The caller must call binder_inner_proc_unlock() to release the inner lock
|
|
|
|
* as well as call binder_dec_thread_txn() to release the reference.
|
|
|
|
*
|
|
|
|
* Return: the value of t->from
|
|
|
|
*/
|
|
|
|
static struct binder_thread *binder_get_txn_from_and_acq_inner(
|
|
|
|
struct binder_transaction *t)
|
2011-11-30 20:18:14 +09:00
|
|
|
{
|
2017-06-02 13:36:52 -07:00
|
|
|
struct binder_thread *from;
|
2014-05-01 01:30:23 +09:00
|
|
|
|
2017-06-02 13:36:52 -07:00
|
|
|
from = binder_get_txn_from(t);
|
|
|
|
if (!from)
|
|
|
|
return NULL;
|
|
|
|
binder_inner_proc_lock(from->proc);
|
|
|
|
if (t->from) {
|
|
|
|
BUG_ON(from != t->from);
|
|
|
|
return from;
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
2017-06-02 13:36:52 -07:00
|
|
|
binder_inner_proc_unlock(from->proc);
|
|
|
|
binder_thread_dec_tmpref(from);
|
|
|
|
return NULL;
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
|
|
|
|
2017-03-30 18:02:13 -07:00
|
|
|
static void binder_free_transaction(struct binder_transaction *t)
|
2011-11-30 20:18:14 +09:00
|
|
|
{
|
|
|
|
if (t->buffer)
|
|
|
|
t->buffer->transaction = NULL;
|
|
|
|
kfree(t);
|
|
|
|
binder_stats_deleted(BINDER_STAT_TRANSACTION);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void binder_send_failed_reply(struct binder_transaction *t,
|
|
|
|
uint32_t error_code)
|
|
|
|
{
|
|
|
|
struct binder_thread *target_thread;
|
2014-07-13 21:31:05 -03:00
|
|
|
struct binder_transaction *next;
|
2014-05-01 01:30:23 +09:00
|
|
|
|
2011-11-30 20:18:14 +09:00
|
|
|
BUG_ON(t->flags & TF_ONE_WAY);
|
|
|
|
while (1) {
|
2017-06-02 13:36:52 -07:00
|
|
|
target_thread = binder_get_txn_from_and_acq_inner(t);
|
2011-11-30 20:18:14 +09:00
|
|
|
if (target_thread) {
|
2017-04-21 17:35:12 -07:00
|
|
|
binder_debug(BINDER_DEBUG_FAILED_TRANSACTION,
|
|
|
|
"send failed reply for transaction %d to %d:%d\n",
|
|
|
|
t->debug_id,
|
|
|
|
target_thread->proc->pid,
|
|
|
|
target_thread->pid);
|
|
|
|
|
2017-06-02 13:36:52 -07:00
|
|
|
binder_pop_transaction_ilocked(target_thread, t);
|
2017-04-21 17:35:12 -07:00
|
|
|
if (target_thread->reply_error.cmd == BR_OK) {
|
|
|
|
target_thread->reply_error.cmd = error_code;
|
2017-10-19 15:04:46 +02:00
|
|
|
binder_enqueue_thread_work_ilocked(
|
|
|
|
target_thread,
|
|
|
|
&target_thread->reply_error.work);
|
2011-11-30 20:18:14 +09:00
|
|
|
wake_up_interruptible(&target_thread->wait);
|
|
|
|
} else {
|
UPSTREAM: ANDROID: binder: remove WARN() for redundant txn error
binder_send_failed_reply() is called when a synchronous
transaction fails. It reports an error to the thread that
is waiting for the completion. Given that the transaction
is synchronous, there should never be more than 1 error
response to that thread -- this was being asserted with
a WARN().
However, when exercising the driver with syzbot tests, cases
were observed where multiple "synchronous" requests were
sent without waiting for responses, so it is possible that
multiple errors would be reported to the thread. This testing
was conducted with panic_on_warn set which forced the crash.
This is easily reproduced by sending back-to-back
"synchronous" transactions without checking for any
response (eg, set read_size to 0):
bwr.write_buffer = (uintptr_t)&bc1;
bwr.write_size = sizeof(bc1);
bwr.read_buffer = (uintptr_t)&br;
bwr.read_size = 0;
ioctl(fd, BINDER_WRITE_READ, &bwr);
sleep(1);
bwr2.write_buffer = (uintptr_t)&bc2;
bwr2.write_size = sizeof(bc2);
bwr2.read_buffer = (uintptr_t)&br;
bwr2.read_size = 0;
ioctl(fd, BINDER_WRITE_READ, &bwr2);
sleep(1);
The first transaction is sent to the servicemanager and the reply
fails because no VMA is set up by this client. After
binder_send_failed_reply() is called, the BINDER_WORK_RETURN_ERROR
is sitting on the thread's todo list since the read_size was 0 and
the client is not waiting for a response.
The 2nd transaction is sent and the BINDER_WORK_RETURN_ERROR has not
been consumed, so the thread's reply_error.cmd is still set (normally
cleared when the BINDER_WORK_RETURN_ERROR is handled). Therefore
when the servicemanager attempts to reply to the 2nd failed
transaction, the error is already set and it triggers this warning.
This is a user error since it is not waiting for the synchronous
transaction to complete. If it ever does check, it will see an
error.
Changed the WARN() to a pr_warn().
Signed-off-by: Todd Kjos <tkjos@android.com>
Reported-by: syzbot <syzkaller@googlegroups.com>
Cc: stable <stable@vger.kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit e46a3b3ba7509cb7fda0e07bc7c63a2cd90f579b)
Change-Id: I3365b0775ceee37bdb1d868e3ce066c260aa88ea
2018-02-07 12:38:47 -08:00
|
|
|
/*
|
|
|
|
* Cannot get here for normal operation, but
|
|
|
|
* we can if multiple synchronous transactions
|
|
|
|
* are sent without blocking for responses.
|
|
|
|
* Just ignore the 2nd error in this case.
|
|
|
|
*/
|
|
|
|
pr_warn("Unexpected reply error: %u\n",
|
|
|
|
target_thread->reply_error.cmd);
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
2017-06-02 13:36:52 -07:00
|
|
|
binder_inner_proc_unlock(target_thread->proc);
|
2017-05-12 14:42:55 -07:00
|
|
|
binder_thread_dec_tmpref(target_thread);
|
2017-04-21 17:35:12 -07:00
|
|
|
binder_free_transaction(t);
|
2011-11-30 20:18:14 +09:00
|
|
|
return;
|
2014-07-13 21:31:05 -03:00
|
|
|
}
|
|
|
|
next = t->from_parent;
|
|
|
|
|
|
|
|
binder_debug(BINDER_DEBUG_FAILED_TRANSACTION,
|
|
|
|
"send failed reply for transaction %d, target dead\n",
|
|
|
|
t->debug_id);
|
|
|
|
|
2017-03-30 18:02:13 -07:00
|
|
|
binder_free_transaction(t);
|
2014-07-13 21:31:05 -03:00
|
|
|
if (next == NULL) {
|
2011-11-30 20:18:14 +09:00
|
|
|
binder_debug(BINDER_DEBUG_DEAD_BINDER,
|
2014-07-13 21:31:05 -03:00
|
|
|
"reply failed, no target thread at root\n");
|
|
|
|
return;
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
2014-07-13 21:31:05 -03:00
|
|
|
t = next;
|
|
|
|
binder_debug(BINDER_DEBUG_DEAD_BINDER,
|
|
|
|
"reply failed, no target thread -- retry %d\n",
|
|
|
|
t->debug_id);
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-24 15:23:36 +02:00
|
|
|
/**
|
|
|
|
* binder_cleanup_transaction() - cleans up undelivered transaction
|
|
|
|
* @t: transaction that needs to be cleaned up
|
|
|
|
* @reason: reason the transaction wasn't delivered
|
|
|
|
* @error_code: error to return to caller (if synchronous call)
|
|
|
|
*/
|
|
|
|
static void binder_cleanup_transaction(struct binder_transaction *t,
|
|
|
|
const char *reason,
|
|
|
|
uint32_t error_code)
|
|
|
|
{
|
|
|
|
if (t->buffer->target_node && !(t->flags & TF_ONE_WAY)) {
|
|
|
|
binder_send_failed_reply(t, error_code);
|
|
|
|
} else {
|
|
|
|
binder_debug(BINDER_DEBUG_DEAD_TRANSACTION,
|
|
|
|
"undelivered transaction %d, %s\n",
|
|
|
|
t->debug_id, reason);
|
|
|
|
binder_free_transaction(t);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-13 12:06:49 +02:00
|
|
|
/**
|
|
|
|
* binder_validate_object() - checks for a valid metadata object in a buffer.
|
|
|
|
* @buffer: binder_buffer that we're parsing.
|
|
|
|
* @offset: offset in the buffer at which to validate an object.
|
|
|
|
*
|
|
|
|
* Return: If there's a valid metadata object at @offset in @buffer, the
|
|
|
|
* size of that object. Otherwise, it returns zero.
|
|
|
|
*/
|
|
|
|
static size_t binder_validate_object(struct binder_buffer *buffer, u64 offset)
|
|
|
|
{
|
|
|
|
/* Check if we can read a header first */
|
|
|
|
struct binder_object_header *hdr;
|
|
|
|
size_t object_size = 0;
|
|
|
|
|
|
|
|
if (offset > buffer->data_size - sizeof(*hdr) ||
|
|
|
|
buffer->data_size < sizeof(*hdr) ||
|
|
|
|
!IS_ALIGNED(offset, sizeof(u32)))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Ok, now see if we can read a complete object. */
|
|
|
|
hdr = (struct binder_object_header *)(buffer->data + offset);
|
|
|
|
switch (hdr->type) {
|
|
|
|
case BINDER_TYPE_BINDER:
|
|
|
|
case BINDER_TYPE_WEAK_BINDER:
|
|
|
|
case BINDER_TYPE_HANDLE:
|
|
|
|
case BINDER_TYPE_WEAK_HANDLE:
|
|
|
|
object_size = sizeof(struct flat_binder_object);
|
|
|
|
break;
|
|
|
|
case BINDER_TYPE_FD:
|
|
|
|
object_size = sizeof(struct binder_fd_object);
|
|
|
|
break;
|
2016-09-30 14:10:07 +02:00
|
|
|
case BINDER_TYPE_PTR:
|
|
|
|
object_size = sizeof(struct binder_buffer_object);
|
|
|
|
break;
|
2016-10-18 13:58:55 +02:00
|
|
|
case BINDER_TYPE_FDA:
|
|
|
|
object_size = sizeof(struct binder_fd_array_object);
|
|
|
|
break;
|
2016-07-13 12:06:49 +02:00
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (offset <= buffer->data_size - object_size &&
|
|
|
|
buffer->data_size >= object_size)
|
|
|
|
return object_size;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-09-30 14:10:07 +02:00
|
|
|
/**
|
|
|
|
* binder_validate_ptr() - validates binder_buffer_object in a binder_buffer.
|
|
|
|
* @b: binder_buffer containing the object
|
|
|
|
* @index: index in offset array at which the binder_buffer_object is
|
|
|
|
* located
|
|
|
|
* @start: points to the start of the offset array
|
|
|
|
* @num_valid: the number of valid offsets in the offset array
|
|
|
|
*
|
|
|
|
* Return: If @index is within the valid range of the offset array
|
|
|
|
* described by @start and @num_valid, and if there's a valid
|
|
|
|
* binder_buffer_object at the offset found in index @index
|
|
|
|
* of the offset array, that object is returned. Otherwise,
|
|
|
|
* %NULL is returned.
|
|
|
|
* Note that the offset found in index @index itself is not
|
|
|
|
* verified; this function assumes that @num_valid elements
|
|
|
|
* from @start were previously verified to have valid offsets.
|
|
|
|
*/
|
|
|
|
static struct binder_buffer_object *binder_validate_ptr(struct binder_buffer *b,
|
|
|
|
binder_size_t index,
|
|
|
|
binder_size_t *start,
|
|
|
|
binder_size_t num_valid)
|
|
|
|
{
|
|
|
|
struct binder_buffer_object *buffer_obj;
|
|
|
|
binder_size_t *offp;
|
|
|
|
|
|
|
|
if (index >= num_valid)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
offp = start + index;
|
|
|
|
buffer_obj = (struct binder_buffer_object *)(b->data + *offp);
|
|
|
|
if (buffer_obj->hdr.type != BINDER_TYPE_PTR)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return buffer_obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* binder_validate_fixup() - validates pointer/fd fixups happen in order.
|
|
|
|
* @b: transaction buffer
|
|
|
|
* @objects_start start of objects buffer
|
|
|
|
* @buffer: binder_buffer_object in which to fix up
|
|
|
|
* @offset: start offset in @buffer to fix up
|
|
|
|
* @last_obj: last binder_buffer_object that we fixed up in
|
|
|
|
* @last_min_offset: minimum fixup offset in @last_obj
|
|
|
|
*
|
|
|
|
* Return: %true if a fixup in buffer @buffer at offset @offset is
|
|
|
|
* allowed.
|
|
|
|
*
|
|
|
|
* For safety reasons, we only allow fixups inside a buffer to happen
|
|
|
|
* at increasing offsets; additionally, we only allow fixup on the last
|
|
|
|
* buffer object that was verified, or one of its parents.
|
|
|
|
*
|
|
|
|
* Example of what is allowed:
|
|
|
|
*
|
|
|
|
* A
|
|
|
|
* B (parent = A, offset = 0)
|
|
|
|
* C (parent = A, offset = 16)
|
|
|
|
* D (parent = C, offset = 0)
|
|
|
|
* E (parent = A, offset = 32) // min_offset is 16 (C.parent_offset)
|
|
|
|
*
|
|
|
|
* Examples of what is not allowed:
|
|
|
|
*
|
|
|
|
* Decreasing offsets within the same parent:
|
|
|
|
* A
|
|
|
|
* C (parent = A, offset = 16)
|
|
|
|
* B (parent = A, offset = 0) // decreasing offset within A
|
|
|
|
*
|
|
|
|
* Referring to a parent that wasn't the last object or any of its parents:
|
|
|
|
* A
|
|
|
|
* B (parent = A, offset = 0)
|
|
|
|
* C (parent = A, offset = 0)
|
|
|
|
* C (parent = A, offset = 16)
|
|
|
|
* D (parent = B, offset = 0) // B is not A or any of A's parents
|
|
|
|
*/
|
|
|
|
static bool binder_validate_fixup(struct binder_buffer *b,
|
|
|
|
binder_size_t *objects_start,
|
|
|
|
struct binder_buffer_object *buffer,
|
|
|
|
binder_size_t fixup_offset,
|
|
|
|
struct binder_buffer_object *last_obj,
|
|
|
|
binder_size_t last_min_offset)
|
|
|
|
{
|
|
|
|
if (!last_obj) {
|
|
|
|
/* Nothing to fix up in */
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (last_obj != buffer) {
|
|
|
|
/*
|
|
|
|
* Safe to retrieve the parent of last_obj, since it
|
|
|
|
* was already previously verified by the driver.
|
|
|
|
*/
|
|
|
|
if ((last_obj->flags & BINDER_BUFFER_FLAG_HAS_PARENT) == 0)
|
|
|
|
return false;
|
|
|
|
last_min_offset = last_obj->parent_offset + sizeof(uintptr_t);
|
|
|
|
last_obj = (struct binder_buffer_object *)
|
|
|
|
(b->data + *(objects_start + last_obj->parent));
|
|
|
|
}
|
|
|
|
return (fixup_offset >= last_min_offset);
|
|
|
|
}
|
|
|
|
|
2011-11-30 20:18:14 +09:00
|
|
|
static void binder_transaction_buffer_release(struct binder_proc *proc,
|
|
|
|
struct binder_buffer *buffer,
|
2014-02-21 14:40:26 -08:00
|
|
|
binder_size_t *failed_at)
|
2011-11-30 20:18:14 +09:00
|
|
|
{
|
2016-09-30 14:10:07 +02:00
|
|
|
binder_size_t *offp, *off_start, *off_end;
|
2011-11-30 20:18:14 +09:00
|
|
|
int debug_id = buffer->debug_id;
|
|
|
|
|
|
|
|
binder_debug(BINDER_DEBUG_TRANSACTION,
|
2012-10-30 22:35:43 +05:30
|
|
|
"%d buffer release %d, size %zd-%zd, failed at %p\n",
|
2011-11-30 20:18:14 +09:00
|
|
|
proc->pid, buffer->debug_id,
|
|
|
|
buffer->data_size, buffer->offsets_size, failed_at);
|
|
|
|
|
|
|
|
if (buffer->target_node)
|
|
|
|
binder_dec_node(buffer->target_node, 1, 0);
|
|
|
|
|
2016-09-30 14:10:07 +02:00
|
|
|
off_start = (binder_size_t *)(buffer->data +
|
|
|
|
ALIGN(buffer->data_size, sizeof(void *)));
|
2011-11-30 20:18:14 +09:00
|
|
|
if (failed_at)
|
|
|
|
off_end = failed_at;
|
|
|
|
else
|
2016-09-30 14:10:07 +02:00
|
|
|
off_end = (void *)off_start + buffer->offsets_size;
|
|
|
|
for (offp = off_start; offp < off_end; offp++) {
|
2016-07-13 12:06:49 +02:00
|
|
|
struct binder_object_header *hdr;
|
|
|
|
size_t object_size = binder_validate_object(buffer, *offp);
|
2014-05-01 01:30:23 +09:00
|
|
|
|
2016-07-13 12:06:49 +02:00
|
|
|
if (object_size == 0) {
|
|
|
|
pr_err("transaction release %d bad object at offset %lld, size %zd\n",
|
2014-02-21 14:40:26 -08:00
|
|
|
debug_id, (u64)*offp, buffer->data_size);
|
2011-11-30 20:18:14 +09:00
|
|
|
continue;
|
|
|
|
}
|
2016-07-13 12:06:49 +02:00
|
|
|
hdr = (struct binder_object_header *)(buffer->data + *offp);
|
|
|
|
switch (hdr->type) {
|
2011-11-30 20:18:14 +09:00
|
|
|
case BINDER_TYPE_BINDER:
|
|
|
|
case BINDER_TYPE_WEAK_BINDER: {
|
2016-07-13 12:06:49 +02:00
|
|
|
struct flat_binder_object *fp;
|
|
|
|
struct binder_node *node;
|
2014-05-01 01:30:23 +09:00
|
|
|
|
2016-07-13 12:06:49 +02:00
|
|
|
fp = to_flat_binder_object(hdr);
|
|
|
|
node = binder_get_node(proc, fp->binder);
|
2011-11-30 20:18:14 +09:00
|
|
|
if (node == NULL) {
|
2014-02-21 14:40:26 -08:00
|
|
|
pr_err("transaction release %d bad node %016llx\n",
|
|
|
|
debug_id, (u64)fp->binder);
|
2011-11-30 20:18:14 +09:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
binder_debug(BINDER_DEBUG_TRANSACTION,
|
2014-02-21 14:40:26 -08:00
|
|
|
" node %d u%016llx\n",
|
|
|
|
node->debug_id, (u64)node->ptr);
|
2016-07-13 12:06:49 +02:00
|
|
|
binder_dec_node(node, hdr->type == BINDER_TYPE_BINDER,
|
|
|
|
0);
|
2017-05-09 11:08:05 -07:00
|
|
|
binder_put_node(node);
|
2011-11-30 20:18:14 +09:00
|
|
|
} break;
|
|
|
|
case BINDER_TYPE_HANDLE:
|
|
|
|
case BINDER_TYPE_WEAK_HANDLE: {
|
2016-07-13 12:06:49 +02:00
|
|
|
struct flat_binder_object *fp;
|
2017-05-08 09:16:27 -07:00
|
|
|
struct binder_ref_data rdata;
|
|
|
|
int ret;
|
2016-07-13 12:06:49 +02:00
|
|
|
|
|
|
|
fp = to_flat_binder_object(hdr);
|
2017-05-08 09:16:27 -07:00
|
|
|
ret = binder_dec_ref_for_handle(proc, fp->handle,
|
|
|
|
hdr->type == BINDER_TYPE_HANDLE, &rdata);
|
2014-05-01 01:30:23 +09:00
|
|
|
|
2017-05-08 09:16:27 -07:00
|
|
|
if (ret) {
|
|
|
|
pr_err("transaction release %d bad handle %d, ret = %d\n",
|
|
|
|
debug_id, fp->handle, ret);
|
2011-11-30 20:18:14 +09:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
binder_debug(BINDER_DEBUG_TRANSACTION,
|
2017-05-08 09:16:27 -07:00
|
|
|
" ref %d desc %d\n",
|
|
|
|
rdata.debug_id, rdata.desc);
|
2011-11-30 20:18:14 +09:00
|
|
|
} break;
|
|
|
|
|
2016-07-13 12:06:49 +02:00
|
|
|
case BINDER_TYPE_FD: {
|
|
|
|
struct binder_fd_object *fp = to_binder_fd_object(hdr);
|
|
|
|
|
2011-11-30 20:18:14 +09:00
|
|
|
binder_debug(BINDER_DEBUG_TRANSACTION,
|
2016-07-13 12:06:49 +02:00
|
|
|
" fd %d\n", fp->fd);
|
2011-11-30 20:18:14 +09:00
|
|
|
if (failed_at)
|
2016-07-13 12:06:49 +02:00
|
|
|
task_close_fd(proc, fp->fd);
|
|
|
|
} break;
|
2016-09-30 14:10:07 +02:00
|
|
|
case BINDER_TYPE_PTR:
|
|
|
|
/*
|
|
|
|
* Nothing to do here, this will get cleaned up when the
|
|
|
|
* transaction buffer gets freed
|
|
|
|
*/
|
|
|
|
break;
|
2016-10-18 13:58:55 +02:00
|
|
|
case BINDER_TYPE_FDA: {
|
|
|
|
struct binder_fd_array_object *fda;
|
|
|
|
struct binder_buffer_object *parent;
|
|
|
|
uintptr_t parent_buffer;
|
|
|
|
u32 *fd_array;
|
|
|
|
size_t fd_index;
|
|
|
|
binder_size_t fd_buf_size;
|
|
|
|
|
|
|
|
fda = to_binder_fd_array_object(hdr);
|
|
|
|
parent = binder_validate_ptr(buffer, fda->parent,
|
|
|
|
off_start,
|
|
|
|
offp - off_start);
|
|
|
|
if (!parent) {
|
|
|
|
pr_err("transaction release %d bad parent offset",
|
|
|
|
debug_id);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Since the parent was already fixed up, convert it
|
|
|
|
* back to kernel address space to access it
|
|
|
|
*/
|
|
|
|
parent_buffer = parent->buffer -
|
2016-10-10 10:40:53 -07:00
|
|
|
binder_alloc_get_user_buffer_offset(
|
|
|
|
&proc->alloc);
|
2016-10-18 13:58:55 +02:00
|
|
|
|
|
|
|
fd_buf_size = sizeof(u32) * fda->num_fds;
|
|
|
|
if (fda->num_fds >= SIZE_MAX / sizeof(u32)) {
|
|
|
|
pr_err("transaction release %d invalid number of fds (%lld)\n",
|
|
|
|
debug_id, (u64)fda->num_fds);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (fd_buf_size > parent->length ||
|
|
|
|
fda->parent_offset > parent->length - fd_buf_size) {
|
|
|
|
/* No space for all file descriptors here. */
|
|
|
|
pr_err("transaction release %d not enough space for %lld fds in buffer\n",
|
|
|
|
debug_id, (u64)fda->num_fds);
|
|
|
|
continue;
|
|
|
|
}
|
2017-09-05 10:56:13 +02:00
|
|
|
fd_array = (u32 *)(parent_buffer + (uintptr_t)fda->parent_offset);
|
2016-10-18 13:58:55 +02:00
|
|
|
for (fd_index = 0; fd_index < fda->num_fds; fd_index++)
|
|
|
|
task_close_fd(proc, fd_array[fd_index]);
|
|
|
|
} break;
|
2011-11-30 20:18:14 +09:00
|
|
|
default:
|
2013-07-04 10:54:48 +01:00
|
|
|
pr_err("transaction release %d bad object type %x\n",
|
2016-07-13 12:06:49 +02:00
|
|
|
debug_id, hdr->type);
|
2011-11-30 20:18:14 +09:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-29 15:38:14 +02:00
|
|
|
static int binder_translate_binder(struct flat_binder_object *fp,
|
|
|
|
struct binder_transaction *t,
|
|
|
|
struct binder_thread *thread)
|
|
|
|
{
|
|
|
|
struct binder_node *node;
|
|
|
|
struct binder_proc *proc = thread->proc;
|
|
|
|
struct binder_proc *target_proc = t->to_proc;
|
2017-05-08 09:16:27 -07:00
|
|
|
struct binder_ref_data rdata;
|
2017-05-09 11:08:05 -07:00
|
|
|
int ret = 0;
|
2016-09-29 15:38:14 +02:00
|
|
|
|
|
|
|
node = binder_get_node(proc, fp->binder);
|
|
|
|
if (!node) {
|
2017-06-08 13:45:59 -07:00
|
|
|
node = binder_new_node(proc, fp);
|
2016-09-29 15:38:14 +02:00
|
|
|
if (!node)
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
if (fp->cookie != node->cookie) {
|
|
|
|
binder_user_error("%d:%d sending u%016llx node %d, cookie mismatch %016llx != %016llx\n",
|
|
|
|
proc->pid, thread->pid, (u64)fp->binder,
|
|
|
|
node->debug_id, (u64)fp->cookie,
|
|
|
|
(u64)node->cookie);
|
2017-05-09 11:08:05 -07:00
|
|
|
ret = -EINVAL;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
if (security_binder_transfer_binder(proc->tsk, target_proc->tsk)) {
|
|
|
|
ret = -EPERM;
|
|
|
|
goto done;
|
2016-09-29 15:38:14 +02:00
|
|
|
}
|
|
|
|
|
2017-05-08 09:16:27 -07:00
|
|
|
ret = binder_inc_ref_for_node(target_proc, node,
|
|
|
|
fp->hdr.type == BINDER_TYPE_BINDER,
|
|
|
|
&thread->todo, &rdata);
|
|
|
|
if (ret)
|
2017-05-09 11:08:05 -07:00
|
|
|
goto done;
|
2016-09-29 15:38:14 +02:00
|
|
|
|
|
|
|
if (fp->hdr.type == BINDER_TYPE_BINDER)
|
|
|
|
fp->hdr.type = BINDER_TYPE_HANDLE;
|
|
|
|
else
|
|
|
|
fp->hdr.type = BINDER_TYPE_WEAK_HANDLE;
|
|
|
|
fp->binder = 0;
|
2017-05-08 09:16:27 -07:00
|
|
|
fp->handle = rdata.desc;
|
2016-09-29 15:38:14 +02:00
|
|
|
fp->cookie = 0;
|
|
|
|
|
2017-05-08 09:16:27 -07:00
|
|
|
trace_binder_transaction_node_to_ref(t, node, &rdata);
|
2016-09-29 15:38:14 +02:00
|
|
|
binder_debug(BINDER_DEBUG_TRANSACTION,
|
|
|
|
" node %d u%016llx -> ref %d desc %d\n",
|
|
|
|
node->debug_id, (u64)node->ptr,
|
2017-05-08 09:16:27 -07:00
|
|
|
rdata.debug_id, rdata.desc);
|
2017-05-09 11:08:05 -07:00
|
|
|
done:
|
|
|
|
binder_put_node(node);
|
|
|
|
return ret;
|
2016-09-29 15:38:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static int binder_translate_handle(struct flat_binder_object *fp,
|
|
|
|
struct binder_transaction *t,
|
|
|
|
struct binder_thread *thread)
|
|
|
|
{
|
|
|
|
struct binder_proc *proc = thread->proc;
|
|
|
|
struct binder_proc *target_proc = t->to_proc;
|
2017-05-08 09:16:27 -07:00
|
|
|
struct binder_node *node;
|
|
|
|
struct binder_ref_data src_rdata;
|
2017-05-09 11:08:05 -07:00
|
|
|
int ret = 0;
|
2016-09-29 15:38:14 +02:00
|
|
|
|
2017-05-08 09:16:27 -07:00
|
|
|
node = binder_get_node_from_ref(proc, fp->handle,
|
|
|
|
fp->hdr.type == BINDER_TYPE_HANDLE, &src_rdata);
|
|
|
|
if (!node) {
|
2016-09-29 15:38:14 +02:00
|
|
|
binder_user_error("%d:%d got transaction with invalid handle, %d\n",
|
|
|
|
proc->pid, thread->pid, fp->handle);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2017-05-09 11:08:05 -07:00
|
|
|
if (security_binder_transfer_binder(proc->tsk, target_proc->tsk)) {
|
|
|
|
ret = -EPERM;
|
|
|
|
goto done;
|
|
|
|
}
|
2016-09-29 15:38:14 +02:00
|
|
|
|
2017-06-08 13:45:59 -07:00
|
|
|
binder_node_lock(node);
|
2017-05-08 09:16:27 -07:00
|
|
|
if (node->proc == target_proc) {
|
2016-09-29 15:38:14 +02:00
|
|
|
if (fp->hdr.type == BINDER_TYPE_HANDLE)
|
|
|
|
fp->hdr.type = BINDER_TYPE_BINDER;
|
|
|
|
else
|
|
|
|
fp->hdr.type = BINDER_TYPE_WEAK_BINDER;
|
2017-05-08 09:16:27 -07:00
|
|
|
fp->binder = node->ptr;
|
|
|
|
fp->cookie = node->cookie;
|
2017-06-08 13:45:59 -07:00
|
|
|
if (node->proc)
|
|
|
|
binder_inner_proc_lock(node->proc);
|
|
|
|
binder_inc_node_nilocked(node,
|
|
|
|
fp->hdr.type == BINDER_TYPE_BINDER,
|
|
|
|
0, NULL);
|
|
|
|
if (node->proc)
|
|
|
|
binder_inner_proc_unlock(node->proc);
|
2017-05-08 09:16:27 -07:00
|
|
|
trace_binder_transaction_ref_to_node(t, node, &src_rdata);
|
2016-09-29 15:38:14 +02:00
|
|
|
binder_debug(BINDER_DEBUG_TRANSACTION,
|
|
|
|
" ref %d desc %d -> node %d u%016llx\n",
|
2017-05-08 09:16:27 -07:00
|
|
|
src_rdata.debug_id, src_rdata.desc, node->debug_id,
|
|
|
|
(u64)node->ptr);
|
2017-06-08 13:45:59 -07:00
|
|
|
binder_node_unlock(node);
|
2016-09-29 15:38:14 +02:00
|
|
|
} else {
|
2017-05-08 09:16:27 -07:00
|
|
|
struct binder_ref_data dest_rdata;
|
2016-09-29 15:38:14 +02:00
|
|
|
|
2017-06-08 13:45:59 -07:00
|
|
|
binder_node_unlock(node);
|
2017-05-08 09:16:27 -07:00
|
|
|
ret = binder_inc_ref_for_node(target_proc, node,
|
|
|
|
fp->hdr.type == BINDER_TYPE_HANDLE,
|
|
|
|
NULL, &dest_rdata);
|
|
|
|
if (ret)
|
2017-05-09 11:08:05 -07:00
|
|
|
goto done;
|
2016-09-29 15:38:14 +02:00
|
|
|
|
|
|
|
fp->binder = 0;
|
2017-05-08 09:16:27 -07:00
|
|
|
fp->handle = dest_rdata.desc;
|
2016-09-29 15:38:14 +02:00
|
|
|
fp->cookie = 0;
|
2017-05-08 09:16:27 -07:00
|
|
|
trace_binder_transaction_ref_to_ref(t, node, &src_rdata,
|
|
|
|
&dest_rdata);
|
2016-09-29 15:38:14 +02:00
|
|
|
binder_debug(BINDER_DEBUG_TRANSACTION,
|
|
|
|
" ref %d desc %d -> ref %d desc %d (node %d)\n",
|
2017-05-08 09:16:27 -07:00
|
|
|
src_rdata.debug_id, src_rdata.desc,
|
|
|
|
dest_rdata.debug_id, dest_rdata.desc,
|
|
|
|
node->debug_id);
|
2016-09-29 15:38:14 +02:00
|
|
|
}
|
2017-05-09 11:08:05 -07:00
|
|
|
done:
|
|
|
|
binder_put_node(node);
|
|
|
|
return ret;
|
2016-09-29 15:38:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static int binder_translate_fd(int fd,
|
|
|
|
struct binder_transaction *t,
|
|
|
|
struct binder_thread *thread,
|
|
|
|
struct binder_transaction *in_reply_to)
|
|
|
|
{
|
|
|
|
struct binder_proc *proc = thread->proc;
|
|
|
|
struct binder_proc *target_proc = t->to_proc;
|
|
|
|
int target_fd;
|
|
|
|
struct file *file;
|
|
|
|
int ret;
|
|
|
|
bool target_allows_fd;
|
|
|
|
|
|
|
|
if (in_reply_to)
|
|
|
|
target_allows_fd = !!(in_reply_to->flags & TF_ACCEPT_FDS);
|
|
|
|
else
|
|
|
|
target_allows_fd = t->buffer->target_node->accept_fds;
|
|
|
|
if (!target_allows_fd) {
|
|
|
|
binder_user_error("%d:%d got %s with fd, %d, but target does not allow fds\n",
|
|
|
|
proc->pid, thread->pid,
|
|
|
|
in_reply_to ? "reply" : "transaction",
|
|
|
|
fd);
|
|
|
|
ret = -EPERM;
|
|
|
|
goto err_fd_not_accepted;
|
|
|
|
}
|
|
|
|
|
|
|
|
file = fget(fd);
|
|
|
|
if (!file) {
|
|
|
|
binder_user_error("%d:%d got transaction with invalid fd, %d\n",
|
|
|
|
proc->pid, thread->pid, fd);
|
|
|
|
ret = -EBADF;
|
|
|
|
goto err_fget;
|
|
|
|
}
|
|
|
|
ret = security_binder_transfer_file(proc->tsk, target_proc->tsk, file);
|
|
|
|
if (ret < 0) {
|
|
|
|
ret = -EPERM;
|
|
|
|
goto err_security;
|
|
|
|
}
|
|
|
|
|
|
|
|
target_fd = task_get_unused_fd_flags(target_proc, O_CLOEXEC);
|
|
|
|
if (target_fd < 0) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto err_get_unused_fd;
|
|
|
|
}
|
|
|
|
task_fd_install(target_proc, target_fd, file);
|
|
|
|
trace_binder_transaction_fd(t, fd, target_fd);
|
|
|
|
binder_debug(BINDER_DEBUG_TRANSACTION, " fd %d -> %d\n",
|
|
|
|
fd, target_fd);
|
|
|
|
|
|
|
|
return target_fd;
|
|
|
|
|
|
|
|
err_get_unused_fd:
|
|
|
|
err_security:
|
|
|
|
fput(file);
|
|
|
|
err_fget:
|
|
|
|
err_fd_not_accepted:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-10-18 13:58:55 +02:00
|
|
|
static int binder_translate_fd_array(struct binder_fd_array_object *fda,
|
|
|
|
struct binder_buffer_object *parent,
|
|
|
|
struct binder_transaction *t,
|
|
|
|
struct binder_thread *thread,
|
|
|
|
struct binder_transaction *in_reply_to)
|
|
|
|
{
|
|
|
|
binder_size_t fdi, fd_buf_size, num_installed_fds;
|
|
|
|
int target_fd;
|
|
|
|
uintptr_t parent_buffer;
|
|
|
|
u32 *fd_array;
|
|
|
|
struct binder_proc *proc = thread->proc;
|
|
|
|
struct binder_proc *target_proc = t->to_proc;
|
|
|
|
|
|
|
|
fd_buf_size = sizeof(u32) * fda->num_fds;
|
|
|
|
if (fda->num_fds >= SIZE_MAX / sizeof(u32)) {
|
|
|
|
binder_user_error("%d:%d got transaction with invalid number of fds (%lld)\n",
|
|
|
|
proc->pid, thread->pid, (u64)fda->num_fds);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
if (fd_buf_size > parent->length ||
|
|
|
|
fda->parent_offset > parent->length - fd_buf_size) {
|
|
|
|
/* No space for all file descriptors here. */
|
|
|
|
binder_user_error("%d:%d not enough space to store %lld fds in buffer\n",
|
|
|
|
proc->pid, thread->pid, (u64)fda->num_fds);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Since the parent was already fixed up, convert it
|
|
|
|
* back to the kernel address space to access it
|
|
|
|
*/
|
2016-10-10 10:40:53 -07:00
|
|
|
parent_buffer = parent->buffer -
|
|
|
|
binder_alloc_get_user_buffer_offset(&target_proc->alloc);
|
2017-09-05 10:56:13 +02:00
|
|
|
fd_array = (u32 *)(parent_buffer + (uintptr_t)fda->parent_offset);
|
2016-10-18 13:58:55 +02:00
|
|
|
if (!IS_ALIGNED((unsigned long)fd_array, sizeof(u32))) {
|
|
|
|
binder_user_error("%d:%d parent offset not aligned correctly.\n",
|
|
|
|
proc->pid, thread->pid);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
for (fdi = 0; fdi < fda->num_fds; fdi++) {
|
|
|
|
target_fd = binder_translate_fd(fd_array[fdi], t, thread,
|
|
|
|
in_reply_to);
|
|
|
|
if (target_fd < 0)
|
|
|
|
goto err_translate_fd_failed;
|
|
|
|
fd_array[fdi] = target_fd;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_translate_fd_failed:
|
|
|
|
/*
|
|
|
|
* Failed to allocate fd or security error, free fds
|
|
|
|
* installed so far.
|
|
|
|
*/
|
|
|
|
num_installed_fds = fdi;
|
|
|
|
for (fdi = 0; fdi < num_installed_fds; fdi++)
|
|
|
|
task_close_fd(target_proc, fd_array[fdi]);
|
|
|
|
return target_fd;
|
|
|
|
}
|
|
|
|
|
2016-09-30 14:10:07 +02:00
|
|
|
static int binder_fixup_parent(struct binder_transaction *t,
|
|
|
|
struct binder_thread *thread,
|
|
|
|
struct binder_buffer_object *bp,
|
|
|
|
binder_size_t *off_start,
|
|
|
|
binder_size_t num_valid,
|
|
|
|
struct binder_buffer_object *last_fixup_obj,
|
|
|
|
binder_size_t last_fixup_min_off)
|
|
|
|
{
|
|
|
|
struct binder_buffer_object *parent;
|
|
|
|
u8 *parent_buffer;
|
|
|
|
struct binder_buffer *b = t->buffer;
|
|
|
|
struct binder_proc *proc = thread->proc;
|
|
|
|
struct binder_proc *target_proc = t->to_proc;
|
|
|
|
|
|
|
|
if (!(bp->flags & BINDER_BUFFER_FLAG_HAS_PARENT))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
parent = binder_validate_ptr(b, bp->parent, off_start, num_valid);
|
|
|
|
if (!parent) {
|
|
|
|
binder_user_error("%d:%d got transaction with invalid parent offset or type\n",
|
|
|
|
proc->pid, thread->pid);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!binder_validate_fixup(b, off_start,
|
|
|
|
parent, bp->parent_offset,
|
|
|
|
last_fixup_obj,
|
|
|
|
last_fixup_min_off)) {
|
|
|
|
binder_user_error("%d:%d got transaction with out-of-order buffer fixup\n",
|
|
|
|
proc->pid, thread->pid);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parent->length < sizeof(binder_uintptr_t) ||
|
|
|
|
bp->parent_offset > parent->length - sizeof(binder_uintptr_t)) {
|
|
|
|
/* No space for a pointer here! */
|
|
|
|
binder_user_error("%d:%d got transaction with invalid parent offset\n",
|
|
|
|
proc->pid, thread->pid);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2017-09-05 10:56:13 +02:00
|
|
|
parent_buffer = (u8 *)((uintptr_t)parent->buffer -
|
2016-10-10 10:40:53 -07:00
|
|
|
binder_alloc_get_user_buffer_offset(
|
|
|
|
&target_proc->alloc));
|
2016-09-30 14:10:07 +02:00
|
|
|
*(binder_uintptr_t *)(parent_buffer + bp->parent_offset) = bp->buffer;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-06-06 15:17:46 -07:00
|
|
|
/**
|
|
|
|
* binder_proc_transaction() - sends a transaction to a process and wakes it up
|
|
|
|
* @t: transaction to send
|
|
|
|
* @proc: process to send the transaction to
|
|
|
|
* @thread: thread in @proc to send the transaction to (may be NULL)
|
|
|
|
*
|
|
|
|
* This function queues a transaction to the specified process. It will try
|
|
|
|
* to find a thread in the target process to handle the transaction and
|
|
|
|
* wake it up. If no thread is found, the work is queued to the proc
|
|
|
|
* waitqueue.
|
|
|
|
*
|
|
|
|
* If the @thread parameter is not NULL, the transaction is always queued
|
|
|
|
* to the waitlist of that specific thread.
|
|
|
|
*
|
|
|
|
* Return: true if the transactions was successfully queued
|
|
|
|
* false if the target process or thread is dead
|
|
|
|
*/
|
|
|
|
static bool binder_proc_transaction(struct binder_transaction *t,
|
|
|
|
struct binder_proc *proc,
|
|
|
|
struct binder_thread *thread)
|
|
|
|
{
|
|
|
|
struct binder_node *node = t->buffer->target_node;
|
2017-06-07 10:02:12 -07:00
|
|
|
struct binder_priority node_prio;
|
2017-06-06 15:17:46 -07:00
|
|
|
bool oneway = !!(t->flags & TF_ONE_WAY);
|
2017-10-19 15:04:46 +02:00
|
|
|
bool pending_async = false;
|
2017-06-06 15:17:46 -07:00
|
|
|
|
|
|
|
BUG_ON(!node);
|
|
|
|
binder_node_lock(node);
|
2017-06-07 10:02:12 -07:00
|
|
|
node_prio.prio = node->min_priority;
|
|
|
|
node_prio.sched_policy = node->sched_policy;
|
|
|
|
|
2017-06-06 15:17:46 -07:00
|
|
|
if (oneway) {
|
|
|
|
BUG_ON(thread);
|
|
|
|
if (node->has_async_transaction) {
|
2017-10-19 15:04:46 +02:00
|
|
|
pending_async = true;
|
2017-06-06 15:17:46 -07:00
|
|
|
} else {
|
|
|
|
node->has_async_transaction = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
binder_inner_proc_lock(proc);
|
|
|
|
|
|
|
|
if (proc->is_dead || (thread && thread->is_dead)) {
|
|
|
|
binder_inner_proc_unlock(proc);
|
|
|
|
binder_node_unlock(node);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-10-19 15:04:46 +02:00
|
|
|
if (!thread && !pending_async)
|
2017-06-06 15:17:46 -07:00
|
|
|
thread = binder_select_thread_ilocked(proc);
|
|
|
|
|
2017-06-07 10:02:12 -07:00
|
|
|
if (thread) {
|
2017-06-23 10:13:43 -07:00
|
|
|
binder_transaction_priority(thread->task, t, node_prio,
|
|
|
|
node->inherit_rt);
|
2017-10-19 15:04:46 +02:00
|
|
|
binder_enqueue_thread_work_ilocked(thread, &t->work);
|
|
|
|
} else if (!pending_async) {
|
|
|
|
binder_enqueue_work_ilocked(&t->work, &proc->todo);
|
2017-06-07 10:02:12 -07:00
|
|
|
} else {
|
2017-10-19 15:04:46 +02:00
|
|
|
binder_enqueue_work_ilocked(&t->work, &node->async_todo);
|
2017-06-07 10:02:12 -07:00
|
|
|
}
|
2017-06-06 15:17:46 -07:00
|
|
|
|
2017-10-19 15:04:46 +02:00
|
|
|
if (!pending_async)
|
2017-06-06 15:17:46 -07:00
|
|
|
binder_wakeup_thread_ilocked(proc, thread, !oneway /* sync */);
|
|
|
|
|
|
|
|
binder_inner_proc_unlock(proc);
|
|
|
|
binder_node_unlock(node);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-09-25 08:55:09 -07:00
|
|
|
/**
|
|
|
|
* binder_get_node_refs_for_txn() - Get required refs on node for txn
|
|
|
|
* @node: struct binder_node for which to get refs
|
|
|
|
* @proc: returns @node->proc if valid
|
|
|
|
* @error: if no @proc then returns BR_DEAD_REPLY
|
|
|
|
*
|
|
|
|
* User-space normally keeps the node alive when creating a transaction
|
|
|
|
* since it has a reference to the target. The local strong ref keeps it
|
|
|
|
* alive if the sending process dies before the target process processes
|
|
|
|
* the transaction. If the source process is malicious or has a reference
|
|
|
|
* counting bug, relying on the local strong ref can fail.
|
|
|
|
*
|
|
|
|
* Since user-space can cause the local strong ref to go away, we also take
|
|
|
|
* a tmpref on the node to ensure it survives while we are constructing
|
|
|
|
* the transaction. We also need a tmpref on the proc while we are
|
|
|
|
* constructing the transaction, so we take that here as well.
|
|
|
|
*
|
|
|
|
* Return: The target_node with refs taken or NULL if no @node->proc is NULL.
|
|
|
|
* Also sets @proc if valid. If the @node->proc is NULL indicating that the
|
|
|
|
* target proc has died, @error is set to BR_DEAD_REPLY
|
|
|
|
*/
|
|
|
|
static struct binder_node *binder_get_node_refs_for_txn(
|
|
|
|
struct binder_node *node,
|
|
|
|
struct binder_proc **procp,
|
|
|
|
uint32_t *error)
|
|
|
|
{
|
|
|
|
struct binder_node *target_node = NULL;
|
|
|
|
|
|
|
|
binder_node_inner_lock(node);
|
|
|
|
if (node->proc) {
|
|
|
|
target_node = node;
|
|
|
|
binder_inc_node_nilocked(node, 1, 0, NULL);
|
|
|
|
binder_inc_node_tmpref_ilocked(node);
|
|
|
|
node->proc->tmp_ref++;
|
|
|
|
*procp = node->proc;
|
|
|
|
} else
|
|
|
|
*error = BR_DEAD_REPLY;
|
|
|
|
binder_node_inner_unlock(node);
|
|
|
|
|
|
|
|
return target_node;
|
|
|
|
}
|
|
|
|
|
2011-11-30 20:18:14 +09:00
|
|
|
static void binder_transaction(struct binder_proc *proc,
|
|
|
|
struct binder_thread *thread,
|
2016-09-30 14:05:40 +02:00
|
|
|
struct binder_transaction_data *tr, int reply,
|
|
|
|
binder_size_t extra_buffers_size)
|
2011-11-30 20:18:14 +09:00
|
|
|
{
|
2016-09-29 15:38:14 +02:00
|
|
|
int ret;
|
2011-11-30 20:18:14 +09:00
|
|
|
struct binder_transaction *t;
|
|
|
|
struct binder_work *tcomplete;
|
2016-09-30 14:10:07 +02:00
|
|
|
binder_size_t *offp, *off_end, *off_start;
|
2015-11-09 13:08:12 -08:00
|
|
|
binder_size_t off_min;
|
2016-09-30 14:10:07 +02:00
|
|
|
u8 *sg_bufp, *sg_buf_end;
|
2017-05-12 14:42:55 -07:00
|
|
|
struct binder_proc *target_proc = NULL;
|
2011-11-30 20:18:14 +09:00
|
|
|
struct binder_thread *target_thread = NULL;
|
|
|
|
struct binder_node *target_node = NULL;
|
|
|
|
struct binder_transaction *in_reply_to = NULL;
|
|
|
|
struct binder_transaction_log_entry *e;
|
2017-03-22 17:19:52 -07:00
|
|
|
uint32_t return_error = 0;
|
|
|
|
uint32_t return_error_param = 0;
|
|
|
|
uint32_t return_error_line = 0;
|
2016-09-30 14:10:07 +02:00
|
|
|
struct binder_buffer_object *last_fixup_obj = NULL;
|
|
|
|
binder_size_t last_fixup_min_off = 0;
|
2016-09-30 15:51:48 +02:00
|
|
|
struct binder_context *context = proc->context;
|
2017-05-24 13:33:28 -07:00
|
|
|
int t_debug_id = atomic_inc_return(&binder_last_id);
|
2011-11-30 20:18:14 +09:00
|
|
|
|
2017-03-24 15:53:53 -07:00
|
|
|
e = binder_transaction_log_add(&binder_transaction_log);
|
2017-05-24 13:33:28 -07:00
|
|
|
e->debug_id = t_debug_id;
|
2011-11-30 20:18:14 +09:00
|
|
|
e->call_type = reply ? 2 : !!(tr->flags & TF_ONE_WAY);
|
|
|
|
e->from_proc = proc->pid;
|
|
|
|
e->from_thread = thread->pid;
|
|
|
|
e->target_handle = tr->target.handle;
|
|
|
|
e->data_size = tr->data_size;
|
|
|
|
e->offsets_size = tr->offsets_size;
|
2016-10-17 15:17:31 +02:00
|
|
|
e->context_name = proc->context->name;
|
2011-11-30 20:18:14 +09:00
|
|
|
|
|
|
|
if (reply) {
|
2017-06-02 13:36:52 -07:00
|
|
|
binder_inner_proc_lock(proc);
|
2011-11-30 20:18:14 +09:00
|
|
|
in_reply_to = thread->transaction_stack;
|
|
|
|
if (in_reply_to == NULL) {
|
2017-06-02 13:36:52 -07:00
|
|
|
binder_inner_proc_unlock(proc);
|
2012-10-30 22:35:43 +05:30
|
|
|
binder_user_error("%d:%d got reply transaction with no transaction stack\n",
|
2011-11-30 20:18:14 +09:00
|
|
|
proc->pid, thread->pid);
|
|
|
|
return_error = BR_FAILED_REPLY;
|
2017-03-22 17:19:52 -07:00
|
|
|
return_error_param = -EPROTO;
|
|
|
|
return_error_line = __LINE__;
|
2011-11-30 20:18:14 +09:00
|
|
|
goto err_empty_call_stack;
|
|
|
|
}
|
|
|
|
if (in_reply_to->to_thread != thread) {
|
2017-05-12 14:42:55 -07:00
|
|
|
spin_lock(&in_reply_to->lock);
|
2012-10-30 22:35:43 +05:30
|
|
|
binder_user_error("%d:%d got reply transaction with bad transaction stack, transaction %d has target %d:%d\n",
|
2011-11-30 20:18:14 +09:00
|
|
|
proc->pid, thread->pid, in_reply_to->debug_id,
|
|
|
|
in_reply_to->to_proc ?
|
|
|
|
in_reply_to->to_proc->pid : 0,
|
|
|
|
in_reply_to->to_thread ?
|
|
|
|
in_reply_to->to_thread->pid : 0);
|
2017-05-12 14:42:55 -07:00
|
|
|
spin_unlock(&in_reply_to->lock);
|
2017-06-02 13:36:52 -07:00
|
|
|
binder_inner_proc_unlock(proc);
|
2011-11-30 20:18:14 +09:00
|
|
|
return_error = BR_FAILED_REPLY;
|
2017-03-22 17:19:52 -07:00
|
|
|
return_error_param = -EPROTO;
|
|
|
|
return_error_line = __LINE__;
|
2011-11-30 20:18:14 +09:00
|
|
|
in_reply_to = NULL;
|
|
|
|
goto err_bad_call_stack;
|
|
|
|
}
|
|
|
|
thread->transaction_stack = in_reply_to->to_parent;
|
2017-06-02 13:36:52 -07:00
|
|
|
binder_inner_proc_unlock(proc);
|
|
|
|
target_thread = binder_get_txn_from_and_acq_inner(in_reply_to);
|
2011-11-30 20:18:14 +09:00
|
|
|
if (target_thread == NULL) {
|
|
|
|
return_error = BR_DEAD_REPLY;
|
2017-03-22 17:19:52 -07:00
|
|
|
return_error_line = __LINE__;
|
2011-11-30 20:18:14 +09:00
|
|
|
goto err_dead_binder;
|
|
|
|
}
|
|
|
|
if (target_thread->transaction_stack != in_reply_to) {
|
2012-10-30 22:35:43 +05:30
|
|
|
binder_user_error("%d:%d got reply transaction with bad target transaction stack %d, expected %d\n",
|
2011-11-30 20:18:14 +09:00
|
|
|
proc->pid, thread->pid,
|
|
|
|
target_thread->transaction_stack ?
|
|
|
|
target_thread->transaction_stack->debug_id : 0,
|
|
|
|
in_reply_to->debug_id);
|
2017-06-02 13:36:52 -07:00
|
|
|
binder_inner_proc_unlock(target_thread->proc);
|
2011-11-30 20:18:14 +09:00
|
|
|
return_error = BR_FAILED_REPLY;
|
2017-03-22 17:19:52 -07:00
|
|
|
return_error_param = -EPROTO;
|
|
|
|
return_error_line = __LINE__;
|
2011-11-30 20:18:14 +09:00
|
|
|
in_reply_to = NULL;
|
|
|
|
target_thread = NULL;
|
|
|
|
goto err_dead_binder;
|
|
|
|
}
|
|
|
|
target_proc = target_thread->proc;
|
2017-05-12 14:42:55 -07:00
|
|
|
target_proc->tmp_ref++;
|
2017-06-02 13:36:52 -07:00
|
|
|
binder_inner_proc_unlock(target_thread->proc);
|
2011-11-30 20:18:14 +09:00
|
|
|
} else {
|
|
|
|
if (tr->target.handle) {
|
|
|
|
struct binder_ref *ref;
|
2014-05-01 01:30:23 +09:00
|
|
|
|
2017-05-26 11:56:29 -07:00
|
|
|
/*
|
|
|
|
* There must already be a strong ref
|
|
|
|
* on this node. If so, do a strong
|
|
|
|
* increment on the node to ensure it
|
|
|
|
* stays alive until the transaction is
|
|
|
|
* done.
|
|
|
|
*/
|
2016-10-20 16:43:34 -07:00
|
|
|
binder_proc_lock(proc);
|
|
|
|
ref = binder_get_ref_olocked(proc, tr->target.handle,
|
|
|
|
true);
|
2017-05-26 11:56:29 -07:00
|
|
|
if (ref) {
|
2017-09-25 08:55:09 -07:00
|
|
|
target_node = binder_get_node_refs_for_txn(
|
|
|
|
ref->node, &target_proc,
|
|
|
|
&return_error);
|
|
|
|
} else {
|
2012-10-30 22:35:43 +05:30
|
|
|
binder_user_error("%d:%d got transaction to invalid handle\n",
|
2017-09-25 08:55:09 -07:00
|
|
|
proc->pid, thread->pid);
|
2011-11-30 20:18:14 +09:00
|
|
|
return_error = BR_FAILED_REPLY;
|
|
|
|
}
|
2017-09-25 08:55:09 -07:00
|
|
|
binder_proc_unlock(proc);
|
2011-11-30 20:18:14 +09:00
|
|
|
} else {
|
2016-10-17 12:33:15 -07:00
|
|
|
mutex_lock(&context->context_mgr_node_lock);
|
2016-09-30 15:51:48 +02:00
|
|
|
target_node = context->binder_context_mgr_node;
|
2017-09-25 08:55:09 -07:00
|
|
|
if (target_node)
|
|
|
|
target_node = binder_get_node_refs_for_txn(
|
|
|
|
target_node, &target_proc,
|
|
|
|
&return_error);
|
|
|
|
else
|
2011-11-30 20:18:14 +09:00
|
|
|
return_error = BR_DEAD_REPLY;
|
2016-10-17 12:33:15 -07:00
|
|
|
mutex_unlock(&context->context_mgr_node_lock);
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
2017-09-25 08:55:09 -07:00
|
|
|
if (!target_node) {
|
|
|
|
/*
|
|
|
|
* return_error is set above
|
|
|
|
*/
|
|
|
|
return_error_param = -EINVAL;
|
2017-03-22 17:19:52 -07:00
|
|
|
return_error_line = __LINE__;
|
2011-11-30 20:18:14 +09:00
|
|
|
goto err_dead_binder;
|
|
|
|
}
|
2017-09-25 08:55:09 -07:00
|
|
|
e->to_node = target_node->debug_id;
|
2015-01-21 10:54:10 -05:00
|
|
|
if (security_binder_transaction(proc->tsk,
|
|
|
|
target_proc->tsk) < 0) {
|
|
|
|
return_error = BR_FAILED_REPLY;
|
2017-03-22 17:19:52 -07:00
|
|
|
return_error_param = -EPERM;
|
|
|
|
return_error_line = __LINE__;
|
2015-01-21 10:54:10 -05:00
|
|
|
goto err_invalid_target_handle;
|
|
|
|
}
|
2017-06-02 13:36:52 -07:00
|
|
|
binder_inner_proc_lock(proc);
|
2011-11-30 20:18:14 +09:00
|
|
|
if (!(tr->flags & TF_ONE_WAY) && thread->transaction_stack) {
|
|
|
|
struct binder_transaction *tmp;
|
2014-05-01 01:30:23 +09:00
|
|
|
|
2011-11-30 20:18:14 +09:00
|
|
|
tmp = thread->transaction_stack;
|
|
|
|
if (tmp->to_thread != thread) {
|
2017-05-12 14:42:55 -07:00
|
|
|
spin_lock(&tmp->lock);
|
2012-10-30 22:35:43 +05:30
|
|
|
binder_user_error("%d:%d got new transaction with bad transaction stack, transaction %d has target %d:%d\n",
|
2011-11-30 20:18:14 +09:00
|
|
|
proc->pid, thread->pid, tmp->debug_id,
|
|
|
|
tmp->to_proc ? tmp->to_proc->pid : 0,
|
|
|
|
tmp->to_thread ?
|
|
|
|
tmp->to_thread->pid : 0);
|
2017-05-12 14:42:55 -07:00
|
|
|
spin_unlock(&tmp->lock);
|
2017-06-02 13:36:52 -07:00
|
|
|
binder_inner_proc_unlock(proc);
|
2011-11-30 20:18:14 +09:00
|
|
|
return_error = BR_FAILED_REPLY;
|
2017-03-22 17:19:52 -07:00
|
|
|
return_error_param = -EPROTO;
|
|
|
|
return_error_line = __LINE__;
|
2011-11-30 20:18:14 +09:00
|
|
|
goto err_bad_call_stack;
|
|
|
|
}
|
|
|
|
while (tmp) {
|
2017-05-12 14:42:55 -07:00
|
|
|
struct binder_thread *from;
|
|
|
|
|
|
|
|
spin_lock(&tmp->lock);
|
|
|
|
from = tmp->from;
|
|
|
|
if (from && from->proc == target_proc) {
|
|
|
|
atomic_inc(&from->tmp_ref);
|
|
|
|
target_thread = from;
|
|
|
|
spin_unlock(&tmp->lock);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
spin_unlock(&tmp->lock);
|
2011-11-30 20:18:14 +09:00
|
|
|
tmp = tmp->from_parent;
|
|
|
|
}
|
|
|
|
}
|
2017-06-02 13:36:52 -07:00
|
|
|
binder_inner_proc_unlock(proc);
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
2017-06-06 15:17:46 -07:00
|
|
|
if (target_thread)
|
2011-11-30 20:18:14 +09:00
|
|
|
e->to_thread = target_thread->pid;
|
|
|
|
e->to_proc = target_proc->pid;
|
|
|
|
|
|
|
|
/* TODO: reuse incoming transaction for reply */
|
2017-07-26 05:01:18 -07:00
|
|
|
t = kzalloc(sizeof(*t), GFP_KERNEL);
|
2011-11-30 20:18:14 +09:00
|
|
|
if (t == NULL) {
|
|
|
|
return_error = BR_FAILED_REPLY;
|
2017-03-22 17:19:52 -07:00
|
|
|
return_error_param = -ENOMEM;
|
|
|
|
return_error_line = __LINE__;
|
2011-11-30 20:18:14 +09:00
|
|
|
goto err_alloc_t_failed;
|
|
|
|
}
|
|
|
|
binder_stats_created(BINDER_STAT_TRANSACTION);
|
2017-05-12 14:42:55 -07:00
|
|
|
spin_lock_init(&t->lock);
|
2011-11-30 20:18:14 +09:00
|
|
|
|
2017-07-26 05:01:18 -07:00
|
|
|
tcomplete = kzalloc(sizeof(*tcomplete), GFP_KERNEL);
|
2011-11-30 20:18:14 +09:00
|
|
|
if (tcomplete == NULL) {
|
|
|
|
return_error = BR_FAILED_REPLY;
|
2017-03-22 17:19:52 -07:00
|
|
|
return_error_param = -ENOMEM;
|
|
|
|
return_error_line = __LINE__;
|
2011-11-30 20:18:14 +09:00
|
|
|
goto err_alloc_tcomplete_failed;
|
|
|
|
}
|
|
|
|
binder_stats_created(BINDER_STAT_TRANSACTION_COMPLETE);
|
|
|
|
|
2017-05-24 13:33:28 -07:00
|
|
|
t->debug_id = t_debug_id;
|
2011-11-30 20:18:14 +09:00
|
|
|
|
|
|
|
if (reply)
|
|
|
|
binder_debug(BINDER_DEBUG_TRANSACTION,
|
2016-09-30 14:05:40 +02:00
|
|
|
"%d:%d BC_REPLY %d -> %d:%d, data %016llx-%016llx size %lld-%lld-%lld\n",
|
2011-11-30 20:18:14 +09:00
|
|
|
proc->pid, thread->pid, t->debug_id,
|
|
|
|
target_proc->pid, target_thread->pid,
|
2014-02-21 14:40:26 -08:00
|
|
|
(u64)tr->data.ptr.buffer,
|
|
|
|
(u64)tr->data.ptr.offsets,
|
2016-09-30 14:05:40 +02:00
|
|
|
(u64)tr->data_size, (u64)tr->offsets_size,
|
|
|
|
(u64)extra_buffers_size);
|
2011-11-30 20:18:14 +09:00
|
|
|
else
|
|
|
|
binder_debug(BINDER_DEBUG_TRANSACTION,
|
2016-09-30 14:05:40 +02:00
|
|
|
"%d:%d BC_TRANSACTION %d -> %d - node %d, data %016llx-%016llx size %lld-%lld-%lld\n",
|
2011-11-30 20:18:14 +09:00
|
|
|
proc->pid, thread->pid, t->debug_id,
|
|
|
|
target_proc->pid, target_node->debug_id,
|
2014-02-21 14:40:26 -08:00
|
|
|
(u64)tr->data.ptr.buffer,
|
|
|
|
(u64)tr->data.ptr.offsets,
|
2016-09-30 14:05:40 +02:00
|
|
|
(u64)tr->data_size, (u64)tr->offsets_size,
|
|
|
|
(u64)extra_buffers_size);
|
2011-11-30 20:18:14 +09:00
|
|
|
|
|
|
|
if (!reply && !(tr->flags & TF_ONE_WAY))
|
|
|
|
t->from = thread;
|
|
|
|
else
|
|
|
|
t->from = NULL;
|
2014-05-31 22:43:34 +03:00
|
|
|
t->sender_euid = task_euid(proc->tsk);
|
2011-11-30 20:18:14 +09:00
|
|
|
t->to_proc = target_proc;
|
|
|
|
t->to_thread = target_thread;
|
|
|
|
t->code = tr->code;
|
|
|
|
t->flags = tr->flags;
|
2017-06-06 17:04:42 -07:00
|
|
|
if (!(t->flags & TF_ONE_WAY) &&
|
|
|
|
binder_supported_policy(current->policy)) {
|
|
|
|
/* Inherit supported policies for synchronous transactions */
|
|
|
|
t->priority.sched_policy = current->policy;
|
|
|
|
t->priority.prio = current->normal_prio;
|
|
|
|
} else {
|
|
|
|
/* Otherwise, fall back to the default priority */
|
|
|
|
t->priority = target_proc->default_priority;
|
|
|
|
}
|
2012-10-16 15:29:53 -07:00
|
|
|
|
|
|
|
trace_binder_transaction(reply, t, target_node);
|
|
|
|
|
2016-10-10 10:40:53 -07:00
|
|
|
t->buffer = binder_alloc_new_buf(&target_proc->alloc, tr->data_size,
|
2016-09-30 14:05:40 +02:00
|
|
|
tr->offsets_size, extra_buffers_size,
|
|
|
|
!reply && (t->flags & TF_ONE_WAY));
|
2017-03-22 17:19:52 -07:00
|
|
|
if (IS_ERR(t->buffer)) {
|
|
|
|
/*
|
|
|
|
* -ESRCH indicates VMA cleared. The target is dying.
|
|
|
|
*/
|
|
|
|
return_error_param = PTR_ERR(t->buffer);
|
|
|
|
return_error = return_error_param == -ESRCH ?
|
|
|
|
BR_DEAD_REPLY : BR_FAILED_REPLY;
|
|
|
|
return_error_line = __LINE__;
|
|
|
|
t->buffer = NULL;
|
2011-11-30 20:18:14 +09:00
|
|
|
goto err_binder_alloc_buf_failed;
|
|
|
|
}
|
|
|
|
t->buffer->allow_user_free = 0;
|
|
|
|
t->buffer->debug_id = t->debug_id;
|
|
|
|
t->buffer->transaction = t;
|
|
|
|
t->buffer->target_node = target_node;
|
2012-10-16 15:29:53 -07:00
|
|
|
trace_binder_transaction_alloc_buf(t->buffer);
|
2016-09-30 14:10:07 +02:00
|
|
|
off_start = (binder_size_t *)(t->buffer->data +
|
|
|
|
ALIGN(tr->data_size, sizeof(void *)));
|
|
|
|
offp = off_start;
|
2011-11-30 20:18:14 +09:00
|
|
|
|
2017-07-26 05:01:18 -07:00
|
|
|
if (copy_from_user(t->buffer->data, (const void __user *)(uintptr_t)
|
2014-02-21 14:40:26 -08:00
|
|
|
tr->data.ptr.buffer, tr->data_size)) {
|
2012-10-30 22:35:43 +05:30
|
|
|
binder_user_error("%d:%d got transaction with invalid data ptr\n",
|
|
|
|
proc->pid, thread->pid);
|
2011-11-30 20:18:14 +09:00
|
|
|
return_error = BR_FAILED_REPLY;
|
2017-03-22 17:19:52 -07:00
|
|
|
return_error_param = -EFAULT;
|
|
|
|
return_error_line = __LINE__;
|
2011-11-30 20:18:14 +09:00
|
|
|
goto err_copy_data_failed;
|
|
|
|
}
|
2017-07-26 05:01:18 -07:00
|
|
|
if (copy_from_user(offp, (const void __user *)(uintptr_t)
|
2014-02-21 14:40:26 -08:00
|
|
|
tr->data.ptr.offsets, tr->offsets_size)) {
|
2012-10-30 22:35:43 +05:30
|
|
|
binder_user_error("%d:%d got transaction with invalid offsets ptr\n",
|
|
|
|
proc->pid, thread->pid);
|
2011-11-30 20:18:14 +09:00
|
|
|
return_error = BR_FAILED_REPLY;
|
2017-03-22 17:19:52 -07:00
|
|
|
return_error_param = -EFAULT;
|
|
|
|
return_error_line = __LINE__;
|
2011-11-30 20:18:14 +09:00
|
|
|
goto err_copy_data_failed;
|
|
|
|
}
|
2014-02-21 14:40:26 -08:00
|
|
|
if (!IS_ALIGNED(tr->offsets_size, sizeof(binder_size_t))) {
|
|
|
|
binder_user_error("%d:%d got transaction with invalid offsets size, %lld\n",
|
|
|
|
proc->pid, thread->pid, (u64)tr->offsets_size);
|
2011-11-30 20:18:14 +09:00
|
|
|
return_error = BR_FAILED_REPLY;
|
2017-03-22 17:19:52 -07:00
|
|
|
return_error_param = -EINVAL;
|
|
|
|
return_error_line = __LINE__;
|
2011-11-30 20:18:14 +09:00
|
|
|
goto err_bad_offset;
|
|
|
|
}
|
2016-09-30 14:10:07 +02:00
|
|
|
if (!IS_ALIGNED(extra_buffers_size, sizeof(u64))) {
|
Merge tag 'lsk-v4.4-16.12-android' into branch 'msm-4.4'
* remotes/origin/tmp-2f0de51:
Linux 4.4.38
esp6: Fix integrity verification when ESN are used
esp4: Fix integrity verification when ESN are used
ipv4: Set skb->protocol properly for local output
ipv6: Set skb->protocol properly for local output
Don't feed anything but regular iovec's to blk_rq_map_user_iov
constify iov_iter_count() and iter_is_iovec()
sparc64: fix compile warning section mismatch in find_node()
sparc64: Fix find_node warning if numa node cannot be found
sparc32: Fix inverted invalid_frame_pointer checks on sigreturns
net: ping: check minimum size on ICMP header length
net: avoid signed overflows for SO_{SND|RCV}BUFFORCE
geneve: avoid use-after-free of skb->data
sh_eth: remove unchecked interrupts for RZ/A1
net: bcmgenet: Utilize correct struct device for all DMA operations
packet: fix race condition in packet_set_ring
net/dccp: fix use-after-free in dccp_invalid_packet
netlink: Do not schedule work from sk_destruct
netlink: Call cb->done from a worker thread
net/sched: pedit: make sure that offset is valid
net, sched: respect rcu grace period on cls destruction
net: dsa: bcm_sf2: Ensure we re-negotiate EEE during after link change
l2tp: fix racy SOCK_ZAPPED flag check in l2tp_ip{,6}_bind()
rtnetlink: fix FDB size computation
af_unix: conditionally use freezable blocking calls in read
net: sky2: Fix shutdown crash
ip6_tunnel: disable caching when the traffic class is inherited
net: check dead netns for peernet2id_alloc()
virtio-net: add a missing synchronize_net()
Linux 4.4.37
arm64: suspend: Reconfigure PSTATE after resume from idle
arm64: mm: Set PSTATE.PAN from the cpu_enable_pan() call
arm64: cpufeature: Schedule enable() calls instead of calling them via IPI
pwm: Fix device reference leak
mwifiex: printk() overflow with 32-byte SSIDs
PCI: Set Read Completion Boundary to 128 iff Root Port supports it (_HPX)
PCI: Export pcie_find_root_port
rcu: Fix soft lockup for rcu_nocb_kthread
ALSA: pcm : Call kill_fasync() in stream lock
x86/traps: Ignore high word of regs->cs in early_fixup_exception()
kasan: update kasan_global for gcc 7
zram: fix unbalanced idr management at hot removal
ARC: Don't use "+l" inline asm constraint
Linux 4.4.36
scsi: mpt3sas: Unblock device after controller reset
flow_dissect: call init_default_flow_dissectors() earlier
mei: fix return value on disconnection
mei: me: fix place for kaby point device ids.
mei: me: disable driver on SPT SPS firmware
drm/radeon: Ensure vblank interrupt is enabled on DPMS transition to on
mpi: Fix NULL ptr dereference in mpi_powm() [ver #3]
parisc: Also flush data TLB in flush_icache_page_asm
parisc: Fix race in pci-dma.c
parisc: Fix races in parisc_setup_cache_timing()
NFSv4.x: hide array-bounds warning
apparmor: fix change_hat not finding hat after policy replacement
cfg80211: limit scan results cache size
tile: avoid using clocksource_cyc2ns with absolute cycle count
scsi: mpt3sas: Fix secure erase premature termination
Fix USB CB/CBI storage devices with CONFIG_VMAP_STACK=y
USB: serial: ftdi_sio: add support for TI CC3200 LaunchPad
USB: serial: cp210x: add ID for the Zone DPMX
usb: chipidea: move the lock initialization to core file
KVM: x86: check for pic and ioapic presence before use
KVM: x86: drop error recovery in em_jmp_far and em_ret_far
iommu/vt-d: Fix IOMMU lookup for SR-IOV Virtual Functions
iommu/vt-d: Fix PASID table allocation
sched: tune: Fix lacking spinlock initialization
UPSTREAM: trace: Update documentation for mono, mono_raw and boot clock
UPSTREAM: trace: Add an option for boot clock as trace clock
UPSTREAM: timekeeping: Add a fast and NMI safe boot clock
ANDROID: goldfish_pipe: fix allmodconfig build
ANDROID: goldfish: goldfish_pipe: fix locking errors
ANDROID: video: goldfishfb: fix platform_no_drv_owner.cocci warnings
ANDROID: goldfish_pipe: fix call_kern.cocci warnings
arm64: rename ranchu defconfig to ranchu64
ANDROID: arch: x86: disable pic for Android toolchain
ANDROID: goldfish_pipe: An implementation of more parallel pipe
ANDROID: goldfish_pipe: bugfixes and performance improvements.
ANDROID: goldfish: Add goldfish sync driver
ANDROID: goldfish: add ranchu defconfigs
ANDROID: goldfish_audio: Clear audio read buffer status after each read
ANDROID: goldfish_events: no extra EV_SYN; register goldfish
ANDROID: goldfish_fb: Set pixclock = 0
ANDROID: goldfish: Enable ACPI-based enumeration for goldfish audio
ANDROID: goldfish: Enable ACPI-based enumeration for goldfish framebuffer
ANDROID: video: goldfishfb: add devicetree bindings
BACKPORT: staging: goldfish: audio: fix compiliation on arm
BACKPORT: Input: goldfish_events - enable ACPI-based enumeration for goldfish events
BACKPORT: goldfish: Enable ACPI-based enumeration for goldfish battery
BACKPORT: drivers: tty: goldfish: Add device tree bindings
BACKPORT: tty: goldfish: support platform_device with id -1
BACKPORT: Input: goldfish_events - add devicetree bindings
BACKPORT: power: goldfish_battery: add devicetree bindings
BACKPORT: staging: goldfish: audio: add devicetree bindings
ANDROID: usb: gadget: function: cleanup: Add blank line after declaration
cpufreq: sched: Fix kernel crash on accessing sysfs file
usb: gadget: f_mtp: simplify ptp NULL pointer check
cgroup: replace unified-hierarchy.txt with a proper cgroup v2 documentation
cgroup: rename Documentation/cgroups/ to Documentation/cgroup-legacy/
cgroup: replace __DEVEL__sane_behavior with cgroup2 fs type
writeback: initialize inode members that track writeback history
mm: page_alloc: generalize the dirty balance reserve
block: fix module reference leak on put_disk() call for cgroups throttle
Linux 4.4.35
netfilter: nft_dynset: fix element timeout for HZ != 1000
IB/cm: Mark stale CM id's whenever the mad agent was unregistered
IB/uverbs: Fix leak of XRC target QPs
IB/core: Avoid unsigned int overflow in sg_alloc_table
IB/mlx5: Fix fatal error dispatching
IB/mlx5: Use cache line size to select CQE stride
IB/mlx4: Fix create CQ error flow
IB/mlx4: Check gid_index return value
PM / sleep: don't suspend parent when async child suspend_{noirq, late} fails
PM / sleep: fix device reference leak in test_suspend
uwb: fix device reference leaks
mfd: core: Fix device reference leak in mfd_clone_cell
iwlwifi: pcie: fix SPLC structure parsing
rtc: omap: Fix selecting external osc
clk: mmp: mmp2: fix return value check in mmp2_clk_init()
clk: mmp: pxa168: fix return value check in pxa168_clk_init()
clk: mmp: pxa910: fix return value check in pxa910_clk_init()
drm/amdgpu: Attach exclusive fence to prime exported bo's. (v5)
crypto: caam - do not register AES-XTS mode on LP units
ext4: sanity check the block and cluster size at mount time
kbuild: Steal gcc's pie from the very beginning
x86/kexec: add -fno-PIE
scripts/has-stack-protector: add -fno-PIE
kbuild: add -fno-PIE
i2c: mux: fix up dependencies
can: bcm: fix warning in bcm_connect/proc_register
mfd: intel-lpss: Do not put device in reset state on suspend
fuse: fix fuse_write_end() if zero bytes were copied
KVM: Disable irq while unregistering user notifier
KVM: x86: fix missed SRCU usage in kvm_lapic_set_vapic_addr
x86/cpu/AMD: Fix cpu_llc_id for AMD Fam17h systems
Linux 4.4.34
sparc64: Delete now unused user copy fixup functions.
sparc64: Delete now unused user copy assembler helpers.
sparc64: Convert U3copy_{from,to}_user to accurate exception reporting.
sparc64: Convert NG2copy_{from,to}_user to accurate exception reporting.
sparc64: Convert NGcopy_{from,to}_user to accurate exception reporting.
sparc64: Convert NG4copy_{from,to}_user to accurate exception reporting.
sparc64: Convert U1copy_{from,to}_user to accurate exception reporting.
sparc64: Convert GENcopy_{from,to}_user to accurate exception reporting.
sparc64: Convert copy_in_user to accurate exception reporting.
sparc64: Prepare to move to more saner user copy exception handling.
sparc64: Delete __ret_efault.
sparc64: Handle extremely large kernel TLB range flushes more gracefully.
sparc64: Fix illegal relative branches in hypervisor patched TLB cross-call code.
sparc64: Fix instruction count in comment for __hypervisor_flush_tlb_pending.
sparc64: Fix illegal relative branches in hypervisor patched TLB code.
sparc64: Handle extremely large kernel TSB range flushes sanely.
sparc: Handle negative offsets in arch_jump_label_transform
sparc64 mm: Fix base TSB sizing when hugetlb pages are used
sparc: serial: sunhv: fix a double lock bug
sparc: Don't leak context bits into thread->fault_address
tty: Prevent ldisc drivers from re-using stale tty fields
tcp: take care of truncations done by sk_filter()
ipv4: use new_gw for redirect neigh lookup
net: __skb_flow_dissect() must cap its return value
sock: fix sendmmsg for partial sendmsg
fib_trie: Correct /proc/net/route off by one error
sctp: assign assoc_id earlier in __sctp_connect
ipv6: dccp: add missing bind_conflict to dccp_ipv6_mapped
ipv6: dccp: fix out of bound access in dccp_v6_err()
dccp: fix out of bound access in dccp_v4_err()
dccp: do not send reset to already closed sockets
tcp: fix potential memory corruption
ip6_tunnel: Clear IP6CB in ip6tunnel_xmit()
bgmac: stop clearing DMA receive control register right after it is set
net: mangle zero checksum in skb_checksum_help()
net: clear sk_err_soft in sk_clone_lock()
dctcp: avoid bogus doubling of cwnd after loss
ARM: 8485/1: cpuidle: remove cpu parameter from the cpuidle_ops suspend hook
Linux 4.4.33
netfilter: fix namespace handling in nf_log_proc_dostring
btrfs: qgroup: Prevent qgroup->reserved from going subzero
mmc: mxs: Initialize the spinlock prior to using it
ASoC: sun4i-codec: return error code instead of NULL when create_card fails
ACPI / APEI: Fix incorrect return value of ghes_proc()
i40e: fix call of ndo_dflt_bridge_getlink()
hwrng: core - Don't use a stack buffer in add_early_randomness()
lib/genalloc.c: start search from start of chunk
mei: bus: fix received data size check in NFC fixup
iommu/vt-d: Fix dead-locks in disable_dmar_iommu() path
iommu/amd: Free domain id when free a domain of struct dma_ops_domain
tty/serial: at91: fix hardware handshake on Atmel platforms
dmaengine: at_xdmac: fix spurious flag status for mem2mem transfers
drm/i915: Respect alternate_ddc_pin for all DDI ports
KVM: MIPS: Precalculate MMIO load resume PC
scsi: mpt3sas: Fix for block device of raid exists even after deleting raid disk
scsi: qla2xxx: Fix scsi scan hang triggered if adapter fails during init
iio: orientation: hid-sensor-rotation: Add PM function (fix non working driver)
iio: hid-sensors: Increase the precision of scale to fix wrong reading interpretation.
clk: qoriq: Don't allow CPU clocks higher than starting value
toshiba-wmi: Fix loading the driver on non Toshiba laptops
drbd: Fix kernel_sendmsg() usage - potential NULL deref
usb: gadget: u_ether: remove interrupt throttling
USB: cdc-acm: fix TIOCMIWAIT
staging: nvec: remove managed resource from PS2 driver
Revert "staging: nvec: ps2: change serio type to passthrough"
drivers: staging: nvec: remove bogus reset command for PS/2 interface
staging: iio: ad5933: avoid uninitialized variable in error case
pinctrl: cherryview: Prevent possible interrupt storm on resume
pinctrl: cherryview: Serialize register access in suspend/resume
ARC: timer: rtc: implement read loop in "C" vs. inline asm
s390/hypfs: Use get_free_page() instead of kmalloc to ensure page alignment
coredump: fix unfreezable coredumping task
swapfile: fix memory corruption via malformed swapfile
dib0700: fix nec repeat handling
ASoC: cs4270: fix DAPM stream name mismatch
ALSA: info: Limit the proc text input size
ALSA: info: Return error for invalid read/write
arm64: Enable KPROBES/HIBERNATION/CORESIGHT in defconfig
arm64: kvm: allows kvm cpu hotplug
arm64: KVM: Register CPU notifiers when the kernel runs at HYP
arm64: KVM: Skip HYP setup when already running in HYP
arm64: hyp/kvm: Make hyp-stub reject kvm_call_hyp()
arm64: hyp/kvm: Make hyp-stub extensible
arm64: kvm: Move lr save/restore from do_el2_call into EL1
arm64: kvm: deal with kernel symbols outside of linear mapping
arm64: introduce KIMAGE_VADDR as the virtual base of the kernel region
ANDROID: video: adf: Avoid directly referencing user pointers
ANDROID: usb: gadget: audio_source: fix comparison of distinct pointer types
android: binder: support for file-descriptor arrays.
android: binder: support for scatter-gather.
android: binder: add extra size to allocator.
android: binder: refactor binder_transact()
android: binder: support multiple /dev instances.
android: binder: deal with contexts in debugfs.
android: binder: support multiple context managers.
android: binder: split flat_binder_object.
disable aio support in recommended configuration
Linux 4.4.32
scsi: megaraid_sas: fix macro MEGASAS_IS_LOGICAL to avoid regression
drm/radeon: fix DP mode validation
drm/radeon/dp: add back special handling for NUTMEG
drm/amdgpu: fix DP mode validation
drm/amdgpu/dp: add back special handling for NUTMEG
KVM: MIPS: Drop other CPU ASIDs on guest MMU changes
Revert KVM: MIPS: Drop other CPU ASIDs on guest MMU changes
of: silence warnings due to max() usage
packet: on direct_xmit, limit tso and csum to supported devices
sctp: validate chunk len before actually using it
net sched filters: fix notification of filter delete with proper handle
udp: fix IP_CHECKSUM handling
net: sctp, forbid negative length
ipv4: use the right lock for ping_group_range
ipv4: disable BH in set_ping_group_range()
net: add recursion limit to GRO
rtnetlink: Add rtnexthop offload flag to compare mask
bridge: multicast: restore perm router ports on multicast enable
net: pktgen: remove rcu locking in pktgen_change_name()
ipv6: correctly add local routes when lo goes up
ip6_tunnel: fix ip6_tnl_lookup
ipv6: tcp: restore IP6CB for pktoptions skbs
netlink: do not enter direct reclaim from netlink_dump()
packet: call fanout_release, while UNREGISTERING a netdev
net: Add netdev all_adj_list refcnt propagation to fix panic
net/sched: act_vlan: Push skb->data to mac_header prior calling skb_vlan_*() functions
net: pktgen: fix pkt_size
net: fec: set mac address unconditionally
tg3: Avoid NULL pointer dereference in tg3_io_error_detected()
ipmr, ip6mr: fix scheduling while atomic and a deadlock with ipmr_get_route
ip6_gre: fix flowi6_proto value in ip6gre_xmit_other()
tcp: fix a compile error in DBGUNDO()
tcp: fix wrong checksum calculation on MTU probing
net: avoid sk_forward_alloc overflows
tcp: fix overflow in __tcp_retransmit_skb()
arm64/kvm: fix build issue on kvm debug
arm64: ptdump: Indicate whether memory should be faulting
arm64: Add support for ARCH_SUPPORTS_DEBUG_PAGEALLOC
arm64: Drop alloc function from create_mapping
arm64: allow vmalloc regions to be set with set_memory_*
arm64: kernel: implement ACPI parking protocol
arm64: mm: create new fine-grained mappings at boot
arm64: ensure _stext and _etext are page-aligned
arm64: mm: allow passing a pgdir to alloc_init_*
arm64: mm: allocate pagetables anywhere
arm64: mm: use fixmap when creating page tables
arm64: mm: add functions to walk tables in fixmap
arm64: mm: add __{pud,pgd}_populate
arm64: mm: avoid redundant __pa(__va(x))
Linux 4.4.31
HID: usbhid: add ATEN CS962 to list of quirky devices
ubi: fastmap: Fix add_vol() return value test in ubi_attach_fastmap()
kvm: x86: Check memopp before dereference (CVE-2016-8630)
tty: vt, fix bogus division in csi_J
usb: dwc3: Fix size used in dma_free_coherent()
pwm: Unexport children before chip removal
UBI: fastmap: scrub PEB when bitflips are detected in a free PEB EC header
Disable "frame-address" warning
smc91x: avoid self-comparison warning
cgroup: avoid false positive gcc-6 warning
drm/exynos: fix error handling in exynos_drm_subdrv_open
mm/cma: silence warnings due to max() usage
ARM: 8584/1: floppy: avoid gcc-6 warning
powerpc/ptrace: Fix out of bounds array access warning
x86/xen: fix upper bound of pmd loop in xen_cleanhighmap()
perf build: Fix traceevent plugins build race
drm/dp/mst: Check peer device type before attempting EDID read
drm/radeon: drop register readback in cayman_cp_int_cntl_setup
drm/radeon/si_dpm: workaround for SI kickers
drm/radeon/si_dpm: Limit clocks on HD86xx part
Revert "drm/radeon: fix DP link training issue with second 4K monitor"
mmc: dw_mmc-pltfm: fix the potential NULL pointer dereference
scsi: arcmsr: Send SYNCHRONIZE_CACHE command to firmware
scsi: scsi_debug: Fix memory leak if LBP enabled and module is unloaded
scsi: megaraid_sas: Fix data integrity failure for JBOD (passthrough) devices
mac80211: discard multicast and 4-addr A-MSDUs
firewire: net: fix fragmented datagram_size off-by-one
firewire: net: guard against rx buffer overflows
Input: i8042 - add XMG C504 to keyboard reset table
dm mirror: fix read error on recovery after default leg failure
virtio: console: Unlock vqs while freeing buffers
virtio_ring: Make interrupt suppression spec compliant
parisc: Ensure consistent state when switching to kernel stack at syscall entry
ovl: fsync after copy-up
KVM: MIPS: Make ERET handle ERL before EXL
KVM: x86: fix wbinvd_dirty_mask use-after-free
dm: free io_barrier after blk_cleanup_queue call
USB: serial: cp210x: fix tiocmget error handling
tty: limit terminal size to 4M chars
xhci: add restart quirk for Intel Wildcatpoint PCH
hv: do not lose pending heartbeat vmbus packets
vt: clear selection before resizing
Fix potential infoleak in older kernels
GenWQE: Fix bad page access during abort of resource allocation
usb: increase ohci watchdog delay to 275 msec
xhci: use default USB_RESUME_TIMEOUT when resuming ports.
USB: serial: ftdi_sio: add support for Infineon TriBoard TC2X7
USB: serial: fix potential NULL-dereference at probe
usb: gadget: function: u_ether: don't starve tx request queue
mei: txe: don't clean an unprocessed interrupt cause.
ubifs: Fix regression in ubifs_readdir()
ubifs: Abort readdir upon error
btrfs: fix races on root_log_ctx lists
ANDROID: binder: Clear binder and cookie when setting handle in flat binder struct
ANDROID: binder: Add strong ref checks
ALSA: hda - Fix headset mic detection problem for two Dell laptops
ALSA: hda - Adding a new group of pin cfg into ALC295 pin quirk table
ALSA: hda - allow 40 bit DMA mask for NVidia devices
ALSA: hda - Raise AZX_DCAPS_RIRB_DELAY handling into top drivers
ALSA: hda - Merge RIRB_PRE_DELAY into CTX_WORKAROUND caps
ALSA: usb-audio: Add quirk for Syntek STK1160
KEYS: Fix short sprintf buffer in /proc/keys show function
mm: memcontrol: do not recurse in direct reclaim
mm/list_lru.c: avoid error-path NULL pointer deref
libxfs: clean up _calc_dquots_per_chunk
h8300: fix syscall restarting
drm/dp/mst: Clear port->pdt when tearing down the i2c adapter
i2c: core: fix NULL pointer dereference under race condition
i2c: xgene: Avoid dma_buffer overrun
arm64:cpufeature ARM64_NCAPS is the indicator of last feature
arm64: hibernate: Refuse to hibernate if the boot cpu is offline
PM / sleep: Add support for read-only sysfs attributes
arm64: kernel: Add support for hibernate/suspend-to-disk
arm64: mm: add functions to walk page tables by PA
arm64: mm: move pte_* macros
PM / Hibernate: Call flush_icache_range() on pages restored in-place
arm64: Add new asm macro copy_page
arm64: Promote KERNEL_START/KERNEL_END definitions to a header file
arm64: kernel: Include _AC definition in page.h
arm64: Change cpu_resume() to enable mmu early then access sleep_sp by va
arm64: kernel: Rework finisher callback out of __cpu_suspend_enter()
arm64: Cleanup SCTLR flags
arm64: Fold proc-macros.S into assembler.h
arm/arm64: KVM: Add hook for C-based stage2 init
arm/arm64: KVM: Detect vGIC presence at runtime
arm64: KVM: Add support for 16-bit VMID
arm: KVM: Make kvm_arm.h friendly to assembly code
arm/arm64: KVM: Remove unreferenced S2_PGD_ORDER
arm64: KVM: debug: Remove spurious inline attributes
ARM: KVM: Cleanup exception injection
arm64: KVM: Remove weak attributes
arm64: KVM: Cleanup asm-offset.c
arm64: KVM: Turn system register numbers to an enum
arm64: KVM: VHE: Patch out use of HVC
arm64: Add ARM64_HAS_VIRT_HOST_EXTN feature
arm/arm64: Add new is_kernel_in_hyp_mode predicate
arm64: KVM: Move away from the assembly version of the world switch
arm64: KVM: Map the kernel RO section into HYP
arm64: KVM: Add compatibility aliases
arm64: KVM: Implement vgic-v3 save/restore
arm64: KVM: Add panic handling
arm64: KVM: HYP mode entry points
arm64: KVM: Implement TLB handling
arm64: KVM: Implement fpsimd save/restore
arm64: KVM: Implement the core world switch
arm64: KVM: Add patchable function selector
arm64: KVM: Implement guest entry
arm64: KVM: Implement debug save/restore
arm64: KVM: Implement 32bit system register save/restore
arm64: KVM: Implement system register save/restore
arm64: KVM: Implement timer save/restore
arm64: KVM: Implement vgic-v2 save/restore
arm64: KVM: Add a HYP-specific header file
KVM: arm/arm64: vgic-v3: Make the LR indexing macro public
arm64: Add macros to read/write system registers
Linux 4.4.30
Revert "fix minor infoleak in get_user_ex()"
Revert "x86/mm: Expand the exception table logic to allow new handling options"
Linux 4.4.29
ARM: pxa: pxa_cplds: fix interrupt handling
powerpc/nvram: Fix an incorrect partition merge
mpt3sas: Don't spam logs if logging level is 0
perf symbols: Fixup symbol sizes before picking best ones
perf symbols: Check symbol_conf.allow_aliases for kallsyms loading too
perf hists browser: Fix event group display
clk: divider: Fix clk_divider_round_rate() to use clk_readl()
clk: qoriq: fix a register offset error
s390/con3270: fix insufficient space padding
s390/con3270: fix use of uninitialised data
s390/cio: fix accidental interrupt enabling during resume
x86/mm: Expand the exception table logic to allow new handling options
dmaengine: ipu: remove bogus NO_IRQ reference
power: bq24257: Fix use of uninitialized pointer bq->charger
staging: r8188eu: Fix scheduling while atomic splat
ASoC: dapm: Fix kcontrol creation for output driver widget
ASoC: dapm: Fix value setting for _ENUM_DOUBLE MUX's second channel
ASoC: dapm: Fix possible uninitialized variable in snd_soc_dapm_get_volsw()
ASoC: topology: Fix error return code in soc_tplg_dapm_widget_create()
hwrng: omap - Only fail if pm_runtime_get_sync returns < 0
crypto: arm/ghash-ce - add missing async import/export
crypto: gcm - Fix IV buffer size in crypto_gcm_setkey
mwifiex: correct aid value during tdls setup
spi: spi-fsl-dspi: Drop extra spi_master_put in device remove function
ARM: clk-imx35: fix name for ckil clk
uio: fix dmem_region_start computation
genirq/generic_chip: Add irq_unmap callback
perf stat: Fix interval output values
powerpc/eeh: Null check uses of eeh_pe_bus_get
tunnels: Remove encapsulation offloads on decap.
tunnels: Don't apply GRO to multiple layers of encapsulation.
ipip: Properly mark ipip GRO packets as encapsulated.
posix_acl: Clear SGID bit when setting file permissions
brcmfmac: avoid potential stack overflow in brcmf_cfg80211_start_ap()
mm/hugetlb: fix memory offline with hugepage size > memory block size
drm/i915: Unalias obj->phys_handle and obj->userptr
drm/i915: Account for TSEG size when determining 865G stolen base
Revert "drm/i915: Check live status before reading edid"
drm/i915/gen9: fix the WaWmMemoryReadLatency implementation
xenbus: don't look up transaction IDs for ordinary writes
drm/vmwgfx: Limit the user-space command buffer size
drm/radeon: change vblank_time's calculation method to reduce computational error.
drm/radeon/si/dpm: fix phase shedding setup
drm/radeon: narrow asic_init for virtualization
drm/amdgpu: change vblank_time's calculation method to reduce computational error.
drm/amdgpu/dce11: add missing drm_mode_config_cleanup call
drm/amdgpu/dce11: disable hpd on local panels
drm/amdgpu/dce8: disable hpd on local panels
drm/amdgpu/dce10: disable hpd on local panels
drm/amdgpu: fix IB alignment for UVD
drm/prime: Pass the right module owner through to dma_buf_export()
Linux 4.4.28
target: Don't override EXTENDED_COPY xcopy_pt_cmd SCSI status code
target: Make EXTENDED_COPY 0xe4 failure return COPY TARGET DEVICE NOT REACHABLE
target: Re-add missing SCF_ACK_KREF assignment in v4.1.y
ubifs: Fix xattr_names length in exit paths
jbd2: fix incorrect unlock on j_list_lock
ext4: do not advertise encryption support when disabled
mmc: rtsx_usb_sdmmc: Handle runtime PM while changing the led
mmc: rtsx_usb_sdmmc: Avoid keeping the device runtime resumed when unused
mmc: core: Annotate cmd_hdr as __le32
powerpc/mm: Prevent unlikely crash in copro_calculate_slb()
ceph: fix error handling in ceph_read_iter
arm64: kernel: Init MDCR_EL2 even in the absence of a PMU
arm64: percpu: rewrite ll/sc loops in assembly
memstick: rtsx_usb_ms: Manage runtime PM when accessing the device
memstick: rtsx_usb_ms: Runtime resume the device when polling for cards
isofs: Do not return EACCES for unknown filesystems
irqchip/gic-v3-its: Fix entry size mask for GITS_BASER
s390/mm: fix gmap tlb flush issues
Using BUG_ON() as an assert() is _never_ acceptable
mm: filemap: fix mapping->nrpages double accounting in fuse
mm: workingset: fix crash in shadow node shrinker caused by replace_page_cache_page()
acpi, nfit: check for the correct event code in notifications
net/mlx4_core: Allow resetting VF admin mac to zero
bnx2x: Prevent false warning for lack of FC NPIV
PKCS#7: Don't require SpcSpOpusInfo in Authenticode pkcs7 signatures
hpsa: correct skipping masked peripherals
sd: Fix rw_max for devices that report an optimal xfer size
irqchip/gicv3: Handle loop timeout proper
kvm: x86: memset whole irq_eoi
x86/e820: Don't merge consecutive E820_PRAM ranges
blkcg: Unlock blkcg_pol_mutex only once when cpd == NULL
Fix regression which breaks DFS mounting
Cleanup missing frees on some ioctls
Do not send SMB3 SET_INFO request if nothing is changing
SMB3: GUIDs should be constructed as random but valid uuids
Set previous session id correctly on SMB3 reconnect
Display number of credits available
Clarify locking of cifs file and tcon structures and make more granular
fs/cifs: keep guid when assigning fid to fileinfo
cifs: Limit the overall credit acquired
fs/super.c: fix race between freeze_super() and thaw_super()
arc: don't leak bits of kernel stack into coredump
lightnvm: ensure that nvm_dev_ops can be used without CONFIG_NVM
ipc/sem.c: fix complex_count vs. simple op race
mm: filemap: don't plant shadow entries without radix tree node
metag: Only define atomic_dec_if_positive conditionally
scsi: Fix use-after-free
NFSv4.2: Fix a reference leak in nfs42_proc_layoutstats_generic
NFSv4: Open state recovery must account for file permission changes
NFSv4: nfs4_copy_delegation_stateid() must fail if the delegation is invalid
NFSv4: Don't report revoked delegations as valid in nfs_have_delegation()
sunrpc: fix write space race causing stalls
Input: elantech - add Fujitsu Lifebook E556 to force crc_enabled
Input: elantech - force needed quirks on Fujitsu H760
Input: i8042 - skip selftest on ASUS laptops
lib: add "on"/"off" support to kstrtobool
lib: update single-char callers of strtobool()
lib: move strtobool() to kstrtobool()
MIPS: ptrace: Fix regs_return_value for kernel context
MIPS: Fix -mabi=64 build of vdso.lds
ALSA: hda - Fix a failure of micmute led when having multi adcs
cx231xx: fix GPIOs for Pixelview SBTVD hybrid
cx231xx: don't return error on success
mb86a20s: fix demod settings
mb86a20s: fix the locking logic
ovl: copy_up_xattr(): use strnlen
ovl: Fix info leak in ovl_lookup_temp()
fbdev/efifb: Fix 16 color palette entry calculation
scsi: zfcp: spin_lock_irqsave() is not nestable
zfcp: trace full payload of all SAN records (req,resp,iels)
zfcp: fix payload trace length for SAN request&response
zfcp: fix D_ID field with actual value on tracing SAN responses
zfcp: restore tracing of handle for port and LUN with HBA records
zfcp: trace on request for open and close of WKA port
zfcp: restore: Dont use 0 to indicate invalid LUN in rec trace
zfcp: retain trace level for SCSI and HBA FSF response records
zfcp: close window with unblocked rport during rport gone
zfcp: fix ELS/GS request&response length for hardware data router
zfcp: fix fc_host port_type with NPIV
ubi: Deal with interrupted erasures in WL
powerpc/pseries: Fix stack corruption in htpe code
powerpc/64: Fix incorrect return value from __copy_tofrom_user
powerpc/powernv: Use CPU-endian PEST in pnv_pci_dump_p7ioc_diag_data()
powerpc/powernv: Use CPU-endian hub diag-data type in pnv_eeh_get_and_dump_hub_diag()
powerpc/powernv: Pass CPU-endian PE number to opal_pci_eeh_freeze_clear()
powerpc/vdso64: Use double word compare on pointers
dm crypt: fix crash on exit
dm mpath: check if path's request_queue is dying in activate_path()
dm: return correct error code in dm_resume()'s retry loop
dm: mark request_queue dead before destroying the DM device
perf intel-pt: Fix MTC timestamp calculation for large MTC periods
perf intel-pt: Fix estimated timestamps for cycle-accurate mode
perf intel-pt: Fix snapshot overlap detection decoder errors
pstore/ram: Use memcpy_fromio() to save old buffer
pstore/ram: Use memcpy_toio instead of memcpy
pstore/core: drop cmpxchg based updates
pstore/ramoops: fixup driver removal
parisc: Increase initial kernel mapping size
parisc: Fix kernel memory layout regarding position of __gp
parisc: Increase KERNEL_INITIAL_SIZE for 32-bit SMP kernels
cpufreq: intel_pstate: Fix unsafe HWP MSR access
platform: don't return 0 from platform_get_irq[_byname]() on error
PCI: Mark Atheros AR9580 to avoid bus reset
mmc: sdhci: cast unsigned int to unsigned long long to avoid unexpeted error
mmc: block: don't use CMD23 with very old MMC cards
rtlwifi: Fix missing country code for Great Britain
PM / devfreq: event: remove duplicate devfreq_event_get_drvdata()
clk: imx6: initialize GPU clocks
regulator: tps65910: Work around silicon erratum SWCZ010
mei: me: add kaby point device ids
gpio: mpc8xxx: Correct irq handler function
cgroup: Change from CAP_SYS_NICE to CAP_SYS_RESOURCE for cgroup migration permissions
UPSTREAM: cpu/hotplug: Handle unbalanced hotplug enable/disable
UPSTREAM: arm64: kaslr: fix breakage with CONFIG_MODVERSIONS=y
UPSTREAM: arm64: kaslr: keep modules close to the kernel when DYNAMIC_FTRACE=y
cgroup: Remove leftover instances of allow_attach
BACKPORT: lib: harden strncpy_from_user
CHROMIUM: cgroups: relax permissions on moving tasks between cgroups
CHROMIUM: remove Android's cgroup generic permissions checks
Linux 4.4.27
cfq: fix starvation of asynchronous writes
vfs: move permission checking into notify_change() for utimes(NULL)
dlm: free workqueues after the connections
crypto: vmx - Fix memory corruption caused by p8_ghash
crypto: ghash-generic - move common definitions to a new header file
ext4: release bh in make_indexed_dir
ext4: allow DAX writeback for hole punch
ext4: fix memory leak in ext4_insert_range()
ext4: reinforce check of i_dtime when clearing high fields of uid and gid
ext4: enforce online defrag restriction for encrypted files
scsi: ibmvfc: Fix I/O hang when port is not mapped
scsi: arcmsr: Simplify user_len checking
scsi: arcmsr: Buffer overflow in arcmsr_iop_message_xfer()
async_pq_val: fix DMA memory leak
reiserfs: switch to generic_{get,set,remove}xattr()
reiserfs: Unlock superblock before calling reiserfs_quota_on_mount()
ASoC: Intel: Atom: add a missing star in a memcpy call
brcmfmac: fix memory leak in brcmf_fill_bss_param
i40e: avoid NULL pointer dereference and recursive errors on early PCI error
fuse: fix killing s[ug]id in setattr
fuse: invalidate dir dentry after chmod
fuse: listxattr: verify xattr list
drivers: base: dma-mapping: page align the size when unmap_kernel_range
btrfs: assign error values to the correct bio structs
serial: 8250_dw: Check the data->pclk when get apb_pclk
arm64: Use PoU cache instr for I/D coherency
arm64: mm: add code to safely replace TTBR1_EL1
arm64: mm: place __cpu_setup in .text
arm64: add function to install the idmap
arm64: unmap idmap earlier
arm64: unify idmap removal
arm64: mm: place empty_zero_page in bss
arm64: head.S: use memset to clear BSS
arm64: mm: specialise pagetable allocators
arm64: mm: remove pointless PAGE_MASKing
asm-generic: Fix local variable shadow in __set_fixmap_offset
arm64: mm: fold alternatives into .init
ARM: 8511/1: ARM64: kernel: PSCI: move PSCI idle management code to drivers/firmware
ARM: 8481/2: drivers: psci: replace psci firmware calls
ARM: 8480/2: arm64: add implementation for arm-smccc
ARM: 8479/2: add implementation for arm-smccc
ARM: 8478/2: arm/arm64: add arm-smccc
ARM: 8510/1: rework ARM_CPU_SUSPEND dependencies
ARM: 8458/1: bL_switcher: add GIC dependency
Linux 4.4.26
mm: remove gup_flags FOLL_WRITE games from __get_user_pages()
x86/build: Build compressed x86 kernels as PIE
arm64: Remove stack duplicating code from jprobes
arm64: kprobes: Add KASAN instrumentation around stack accesses
arm64: kprobes: Cleanup jprobe_return
arm64: kprobes: Fix overflow when saving stack
arm64: kprobes: WARN if attempting to step with PSTATE.D=1
kprobes: Add arm64 case in kprobe example module
arm64: Add kernel return probes support (kretprobes)
arm64: Add trampoline code for kretprobes
arm64: kprobes instruction simulation support
arm64: Treat all entry code as non-kprobe-able
arm64: Blacklist non-kprobe-able symbol
arm64: Kprobes with single stepping support
arm64: add conditional instruction simulation support
arm64: Add more test functions to insn.c
arm64: Add HAVE_REGS_AND_STACK_ACCESS_API feature
Linux 4.4.25
tpm_crb: fix crb_req_canceled behavior
tpm: fix a race condition in tpm2_unseal_trusted()
ima: use file_dentry()
ARM: cpuidle: Fix error return code
ARM: dts: MSM8064 remove flags from SPMI/MPP IRQs
ARM: dts: mvebu: armada-390: add missing compatibility string and bracket
x86/dumpstack: Fix x86_32 kernel_stack_pointer() previous stack access
x86/irq: Prevent force migration of irqs which are not in the vector domain
x86/boot: Fix kdump, cleanup aborted E820_PRAM max_pfn manipulation
KVM: PPC: BookE: Fix a sanity check
KVM: MIPS: Drop other CPU ASIDs on guest MMU changes
KVM: PPC: Book3s PR: Allow access to unprivileged MMCR2 register
mfd: wm8350-i2c: Make sure the i2c regmap functions are compiled
mfd: 88pm80x: Double shifting bug in suspend/resume
mfd: atmel-hlcdc: Do not sleep in atomic context
mfd: rtsx_usb: Avoid setting ucr->current_sg.status
ALSA: usb-line6: use the same declaration as definition in header for MIDI manufacturer ID
ALSA: usb-audio: Extend DragonFly dB scale quirk to cover other variants
ALSA: ali5451: Fix out-of-bound position reporting
timekeeping: Fix __ktime_get_fast_ns() regression
time: Add cycles to nanoseconds translation
mm: Fix build for hardened usercopy
ANDROID: binder: Clear binder and cookie when setting handle in flat binder struct
ANDROID: binder: Add strong ref checks
UPSTREAM: staging/android/ion : fix a race condition in the ion driver
ANDROID: android-base: CONFIG_HARDENED_USERCOPY=y
UPSTREAM: fs/proc/kcore.c: Add bounce buffer for ktext data
UPSTREAM: fs/proc/kcore.c: Make bounce buffer global for read
BACKPORT: arm64: Correctly bounds check virt_addr_valid
Fix a build breakage in IO latency hist code.
UPSTREAM: efi: include asm/early_ioremap.h not asm/efi.h to get early_memremap
UPSTREAM: ia64: split off early_ioremap() declarations into asm/early_ioremap.h
FROMLIST: arm64: Enable CONFIG_ARM64_SW_TTBR0_PAN
FROMLIST: arm64: xen: Enable user access before a privcmd hvc call
FROMLIST: arm64: Handle faults caused by inadvertent user access with PAN enabled
FROMLIST: arm64: Disable TTBR0_EL1 during normal kernel execution
FROMLIST: arm64: Introduce uaccess_{disable,enable} functionality based on TTBR0_EL1
FROMLIST: arm64: Factor out TTBR0_EL1 post-update workaround into a specific asm macro
FROMLIST: arm64: Factor out PAN enabling/disabling into separate uaccess_* macros
UPSTREAM: arm64: Handle el1 synchronous instruction aborts cleanly
UPSTREAM: arm64: include alternative handling in dcache_by_line_op
UPSTREAM: arm64: fix "dc cvau" cache operation on errata-affected core
UPSTREAM: Revert "arm64: alternatives: add enable parameter to conditional asm macros"
UPSTREAM: arm64: Add new asm macro copy_page
UPSTREAM: arm64: kill ESR_LNX_EXEC
UPSTREAM: arm64: add macro to extract ESR_ELx.EC
UPSTREAM: arm64: mm: mark fault_info table const
UPSTREAM: arm64: fix dump_instr when PAN and UAO are in use
BACKPORT: arm64: Fold proc-macros.S into assembler.h
UPSTREAM: arm64: choose memstart_addr based on minimum sparsemem section alignment
UPSTREAM: arm64/mm: ensure memstart_addr remains sufficiently aligned
UPSTREAM: arm64/kernel: fix incorrect EL0 check in inv_entry macro
UPSTREAM: arm64: Add macros to read/write system registers
UPSTREAM: arm64/efi: refactor EFI init and runtime code for reuse by 32-bit ARM
UPSTREAM: arm64/efi: split off EFI init and runtime code for reuse by 32-bit ARM
UPSTREAM: arm64/efi: mark UEFI reserved regions as MEMBLOCK_NOMAP
BACKPORT: arm64: only consider memblocks with NOMAP cleared for linear mapping
UPSTREAM: mm/memblock: add MEMBLOCK_NOMAP attribute to memblock memory table
ANDROID: dm: android-verity: Remove fec_header location constraint
BACKPORT: audit: consistently record PIDs with task_tgid_nr()
android-base.cfg: Enable kernel ASLR
UPSTREAM: vmlinux.lds.h: allow arch specific handling of ro_after_init data section
UPSTREAM: arm64: spinlock: fix spin_unlock_wait for LSE atomics
UPSTREAM: arm64: avoid TLB conflict with CONFIG_RANDOMIZE_BASE
UPSTREAM: arm64: Only select ARM64_MODULE_PLTS if MODULES=y
sched: Add Kconfig option DEFAULT_USE_ENERGY_AWARE to set ENERGY_AWARE feature flag
sched/fair: remove printk while schedule is in progress
ANDROID: fs: FS tracepoints to track IO.
sched/walt: Drop arch-specific timer access
ANDROID: fiq_debugger: Pass task parameter to unwind_frame()
eas/sched/fair: Fixing comments in find_best_target.
input: keyreset: switch to orderly_reboot
UPSTREAM: tun: fix transmit timestamp support
UPSTREAM: arch/arm/include/asm/pgtable-3level.h: add pmd_mkclean for THP
net: inet: diag: expose the socket mark to privileged processes.
net: diag: make udp_diag_destroy work for mapped addresses.
net: diag: support SOCK_DESTROY for UDP sockets
net: diag: allow socket bytecode filters to match socket marks
net: diag: slightly refactor the inet_diag_bc_audit error checks.
net: diag: Add support to filter on device index
UPSTREAM: brcmfmac: avoid potential stack overflow in brcmf_cfg80211_start_ap()
Linux 4.4.24
ALSA: hda - Add the top speaker pin config for HP Spectre x360
ALSA: hda - Fix headset mic detection problem for several Dell laptops
ACPICA: acpi_get_sleep_type_data: Reduce warnings
ALSA: hda - Adding one more ALC255 pin definition for headset problem
Revert "usbtmc: convert to devm_kzalloc"
USB: serial: cp210x: Add ID for a Juniper console
Staging: fbtft: Fix bug in fbtft-core
usb: misc: legousbtower: Fix NULL pointer deference
USB: serial: cp210x: fix hardware flow-control disable
dm log writes: fix bug with too large bios
clk: xgene: Add missing parenthesis when clearing divider value
aio: mark AIO pseudo-fs noexec
batman-adv: remove unused callback from batadv_algo_ops struct
IB/mlx4: Use correct subnet-prefix in QP1 mads under SR-IOV
IB/mlx4: Fix code indentation in QP1 MAD flow
IB/mlx4: Fix incorrect MC join state bit-masking on SR-IOV
IB/ipoib: Don't allow MC joins during light MC flush
IB/core: Fix use after free in send_leave function
IB/ipoib: Fix memory corruption in ipoib cm mode connect flow
KVM: nVMX: postpone VMCS changes on MSR_IA32_APICBASE write
dmaengine: at_xdmac: fix to pass correct device identity to free_irq()
kernel/fork: fix CLONE_CHILD_CLEARTID regression in nscd
ASoC: omap-mcpdm: Fix irq resource handling
sysctl: handle error writing UINT_MAX to u32 fields
powerpc/prom: Fix sub-processor option passed to ibm, client-architecture-support
brcmsmac: Initialize power in brcms_c_stf_ss_algo_channel_get()
brcmsmac: Free packet if dma_mapping_error() fails in dma_rxfill
brcmfmac: Fix glob_skb leak in brcmf_sdiod_recv_chain
ASoC: Intel: Skylake: Fix error return code in skl_probe()
pNFS/flexfiles: Fix layoutcommit after a commit to DS
pNFS/files: Fix layoutcommit after a commit to DS
NFS: Don't drop CB requests with invalid principals
svc: Avoid garbage replies when pc_func() returns rpc_drop_reply
dmaengine: at_xdmac: fix debug string
fnic: pci_dma_mapping_error() doesn't return an error code
avr32: off by one in at32_init_pio()
ath9k: Fix programming of minCCA power threshold
gspca: avoid unused variable warnings
em28xx-i2c: rt_mutex_trylock() returns zero on failure
NFC: fdp: Detect errors from fdp_nci_create_conn()
iwlmvm: mvm: set correct state in smart-fifo configuration
tile: Define AT_VECTOR_SIZE_ARCH for ARCH_DLINFO
pstore: drop file opened reference count
blk-mq: actually hook up defer list when running requests
hwrng: omap - Fix assumption that runtime_get_sync will always succeed
ARM: sa1111: fix pcmcia suspend/resume
ARM: shmobile: fix regulator quirk for Gen2
ARM: sa1100: clear reset status prior to reboot
ARM: sa1100: fix 3.6864MHz clock
ARM: sa1100: register clocks early
ARM: sun5i: Fix typo in trip point temperature
regulator: qcom_smd: Fix voltage ranges for pm8x41
regulator: qcom_spmi: Update mvs1/mvs2 switches on pm8941
regulator: qcom_spmi: Add support for get_mode/set_mode on switches
regulator: qcom_spmi: Add support for S4 supply on pm8941
tpm: fix byte-order for the value read by tpm2_get_tpm_pt
printk: fix parsing of "brl=" option
MIPS: uprobes: fix use of uninitialised variable
MIPS: Malta: Fix IOCU disable switch read for MIPS64
MIPS: fix uretprobe implementation
MIPS: uprobes: remove incorrect set_orig_insn
arm64: debug: avoid resetting stepping state machine when TIF_SINGLESTEP
ARM: 8618/1: decompressor: reset ttbcr fields to use TTBR0 on ARMv7
irqchip/gicv3: Silence noisy DEBUG_PER_CPU_MAPS warning
gpio: sa1100: fix irq probing for ucb1x00
usb: gadget: fsl_qe_udc: signedness bug in qe_get_frame()
ceph: fix race during filling readdir cache
iwlwifi: mvm: don't use ret when not initialised
iwlwifi: pcie: fix access to scratch buffer
spi: sh-msiof: Avoid invalid clock generator parameters
hwmon: (adt7411) set bit 3 in CFG1 register
nvmem: Declare nvmem_cell_read() consistently
ipvs: fix bind to link-local mcast IPv6 address in backup
tools/vm/slabinfo: fix an unintentional printf
mmc: pxamci: fix potential oops
drivers/perf: arm_pmu: Fix leak in error path
pinctrl: Flag strict is a field in struct pinmux_ops
pinctrl: uniphier: fix .pin_dbg_show() callback
i40e: avoid null pointer dereference
perf/core: Fix pmu::filter_match for SW-led groups
iwlwifi: mvm: fix a few firmware capability checks
usb: musb: fix DMA for host mode
usb: musb: Fix DMA desired mode for Mentor DMA engine
ARM: 8617/1: dma: fix dma_max_pfn()
ARM: 8616/1: dt: Respect property size when parsing CPUs
drm/radeon/si/dpm: add workaround for for Jet parts
drm/nouveau/fifo/nv04: avoid ramht race against cookie insertion
x86/boot: Initialize FPU and X86_FEATURE_ALWAYS even if we don't have CPUID
x86/init: Fix cr4_init_shadow() on CR4-less machines
can: dev: fix deadlock reported after bus-off
mm,ksm: fix endless looping in allocating memory when ksm enable
mtd: nand: davinci: Reinitialize the HW ECC engine in 4bit hwctl
cpuset: handle race between CPU hotplug and cpuset_hotplug_work
usercopy: fold builtin_const check into inline function
Linux 4.4.23
hostfs: Freeing an ERR_PTR in hostfs_fill_sb_common()
qxl: check for kmap failures
power: supply: max17042_battery: fix model download bug.
power_supply: tps65217-charger: fix missing platform_set_drvdata()
PM / hibernate: Fix rtree_next_node() to avoid walking off list ends
PM / hibernate: Restore processor state before using per-CPU variables
MIPS: paravirt: Fix undefined reference to smp_bootstrap
MIPS: Add a missing ".set pop" in an early commit
MIPS: Avoid a BUG warning during prctl(PR_SET_FP_MODE, ...)
MIPS: Remove compact branch policy Kconfig entries
MIPS: vDSO: Fix Malta EVA mapping to vDSO page structs
MIPS: SMP: Fix possibility of deadlock when bringing CPUs online
MIPS: Fix pre-r6 emulation FPU initialisation
i2c: qup: skip qup_i2c_suspend if the device is already runtime suspended
i2c-eg20t: fix race between i2c init and interrupt enable
btrfs: ensure that file descriptor used with subvol ioctls is a dir
nl80211: validate number of probe response CSA counters
can: flexcan: fix resume function
mm: delete unnecessary and unsafe init_tlb_ubc()
tracing: Move mutex to protect against resetting of seq data
fix memory leaks in tracing_buffers_splice_read()
power: reset: hisi-reboot: Unmap region obtained by of_iomap
mtd: pmcmsp-flash: Allocating too much in init_msp_flash()
mtd: maps: sa1100-flash: potential NULL dereference
fix fault_in_multipages_...() on architectures with no-op access_ok()
fanotify: fix list corruption in fanotify_get_response()
fsnotify: add a way to stop queueing events on group shutdown
xfs: prevent dropping ioend completions during buftarg wait
autofs: use dentry flags to block walks during expire
autofs races
pwm: Mark all devices as "might sleep"
bridge: re-introduce 'fix parsing of MLDv2 reports'
net: smc91x: fix SMC accesses
Revert "phy: IRQ cannot be shared"
net: dsa: bcm_sf2: Fix race condition while unmasking interrupts
net/mlx5: Added missing check of msg length in verifying its signature
tipc: fix NULL pointer dereference in shutdown()
net/irda: handle iriap_register_lsap() allocation failure
vti: flush x-netns xfrm cache when vti interface is removed
af_unix: split 'u->readlock' into two: 'iolock' and 'bindlock'
Revert "af_unix: Fix splice-bind deadlock"
bonding: Fix bonding crash
megaraid: fix null pointer check in megasas_detach_one().
nouveau: fix nv40_perfctr_next() cleanup regression
Staging: iio: adc: fix indent on break statement
iwlegacy: avoid warning about missing braces
ath9k: fix misleading indentation
am437x-vfpe: fix typo in vpfe_get_app_input_index
Add braces to avoid "ambiguous ‘else’" compiler warnings
net: caif: fix misleading indentation
Makefile: Mute warning for __builtin_return_address(>0) for tracing only
Disable "frame-address" warning
Disable "maybe-uninitialized" warning globally
gcov: disable -Wmaybe-uninitialized warning
Kbuild: disable 'maybe-uninitialized' warning for CONFIG_PROFILE_ALL_BRANCHES
kbuild: forbid kernel directory to contain spaces and colons
tools: Support relative directory path for 'O='
Makefile: revert "Makefile: Document ability to make file.lst and file.S" partially
kbuild: Do not run modules_install and install in paralel
ocfs2: fix start offset to ocfs2_zero_range_for_truncate()
ocfs2/dlm: fix race between convert and migration
crypto: echainiv - Replace chaining with multiplication
crypto: skcipher - Fix blkcipher walk OOM crash
crypto: arm/aes-ctr - fix NULL dereference in tail processing
crypto: arm64/aes-ctr - fix NULL dereference in tail processing
tcp: properly scale window in tcp_v[46]_reqsk_send_ack()
tcp: fix use after free in tcp_xmit_retransmit_queue()
tcp: cwnd does not increase in TCP YeAH
ipv6: release dst in ping_v6_sendmsg
ipv4: panic in leaf_walk_rcu due to stale node pointer
reiserfs: fix "new_insert_key may be used uninitialized ..."
Fix build warning in kernel/cpuset.c
include/linux/kernel.h: change abs() macro so it uses consistent return type
Linux 4.4.22
openrisc: fix the fix of copy_from_user()
avr32: fix 'undefined reference to `___copy_from_user'
ia64: copy_from_user() should zero the destination on access_ok() failure
genirq/msi: Fix broken debug output
ppc32: fix copy_from_user()
sparc32: fix copy_from_user()
mn10300: copy_from_user() should zero on access_ok() failure...
nios2: copy_from_user() should zero the tail of destination
openrisc: fix copy_from_user()
parisc: fix copy_from_user()
metag: copy_from_user() should zero the destination on access_ok() failure
alpha: fix copy_from_user()
asm-generic: make copy_from_user() zero the destination properly
mips: copy_from_user() must zero the destination on access_ok() failure
hexagon: fix strncpy_from_user() error return
sh: fix copy_from_user()
score: fix copy_from_user() and friends
blackfin: fix copy_from_user()
cris: buggered copy_from_user/copy_to_user/clear_user
frv: fix clear_user()
asm-generic: make get_user() clear the destination on errors
ARC: uaccess: get_user to zero out dest in cause of fault
s390: get_user() should zero on failure
score: fix __get_user/get_user
nios2: fix __get_user()
sh64: failing __get_user() should zero
m32r: fix __get_user()
mn10300: failing __get_user() and get_user() should zero
fix minor infoleak in get_user_ex()
microblaze: fix copy_from_user()
avr32: fix copy_from_user()
microblaze: fix __get_user()
fix iov_iter_fault_in_readable()
irqchip/atmel-aic: Fix potential deadlock in ->xlate()
genirq: Provide irq_gc_{lock_irqsave,unlock_irqrestore}() helpers
drm: Only use compat ioctl for addfb2 on X86/IA64
drm: atmel-hlcdc: Fix vertical scaling
net: simplify napi_synchronize() to avoid warnings
kconfig: tinyconfig: provide whole choice blocks to avoid warnings
soc: qcom/spm: shut up uninitialized variable warning
pinctrl: at91-pio4: use %pr format string for resource
mmc: dw_mmc: use resource_size_t to store physical address
drm/i915: Avoid pointer arithmetic in calculating plane surface offset
mpssd: fix buffer overflow warning
gma500: remove annoying deprecation warning
ipv6: addrconf: fix dev refcont leak when DAD failed
sched/core: Fix a race between try_to_wake_up() and a woken up task
Revert "wext: Fix 32 bit iwpriv compatibility issue with 64 bit Kernel"
ath9k: fix using sta->drv_priv before initializing it
md-cluster: make md-cluster also can work when compiled into kernel
xhci: fix null pointer dereference in stop command timeout function
fuse: direct-io: don't dirty ITER_BVEC pages
Btrfs: remove root_log_ctx from ctx list before btrfs_sync_log returns
crypto: cryptd - initialize child shash_desc on import
arm64: spinlocks: implement smp_mb__before_spinlock() as smp_mb()
pinctrl: sunxi: fix uart1 CTS/RTS pins at PG on A23/A33
pinctrl: pistachio: fix mfio pll_lock pinmux
dm crypt: fix error with too large bios
dm log writes: move IO accounting earlier to fix error path
dm log writes: fix check of kthread_run() return value
bus: arm-ccn: Fix XP watchpoint settings bitmask
bus: arm-ccn: Do not attempt to configure XPs for cycle counter
bus: arm-ccn: Fix PMU handling of MN
ARM: dts: STiH407-family: Provide interconnect clock for consumption in ST SDHCI
ARM: dts: overo: fix gpmc nand on boards with ethernet
ARM: dts: overo: fix gpmc nand cs0 range
ARM: dts: imx6qdl: Fix SPDIF regression
ARM: OMAP3: hwmod data: Add sysc information for DSI
ARM: kirkwood: ib62x0: fix size of u-boot environment partition
ARM: imx6: add missing BM_CLPCR_BYPASS_PMIC_READY setting for imx6sx
ARM: imx6: add missing BM_CLPCR_BYP_MMDC_CH0_LPM_HS setting for imx6ul
ARM: AM43XX: hwmod: Fix RSTST register offset for pruss
cpuset: make sure new tasks conform to the current config of the cpuset
net: thunderx: Fix OOPs with ethtool --register-dump
USB: change bInterval default to 10 ms
ARM: dts: STiH410: Handle interconnect clock required by EHCI/OHCI (USB)
usb: chipidea: udc: fix NULL ptr dereference in isr_setup_status_phase
usb: renesas_usbhs: fix clearing the {BRDY,BEMP}STS condition
USB: serial: simple: add support for another Infineon flashloader
serial: 8250: added acces i/o products quad and octal serial cards
serial: 8250_mid: fix divide error bug if baud rate is 0
iio: ensure ret is initialized to zero before entering do loop
iio:core: fix IIO_VAL_FRACTIONAL sign handling
iio: accel: kxsd9: Fix scaling bug
iio: fix pressure data output unit in hid-sensor-attributes
iio: accel: bmc150: reset chip at init time
iio: adc: at91: unbreak channel adc channel 3
iio: ad799x: Fix buffered capture for ad7991/ad7995/ad7999
iio: adc: ti_am335x_adc: Increase timeout value waiting for ADC sample
iio: adc: ti_am335x_adc: Protect FIFO1 from concurrent access
iio: adc: rockchip_saradc: reset saradc controller before programming it
iio: proximity: as3935: set up buffer timestamps for non-zero values
iio: accel: kxsd9: Fix raw read return
kvm-arm: Unmap shadow pagetables properly
x86/AMD: Apply erratum 665 on machines without a BIOS fix
x86/paravirt: Do not trace _paravirt_ident_*() functions
ARC: mm: fix build breakage with STRICT_MM_TYPECHECKS
IB/uverbs: Fix race between uverbs_close and remove_one
dm flakey: fix reads to be issued if drop_writes configured
audit: fix exe_file access in audit_exe_compare
mm: introduce get_task_exe_file
kexec: fix double-free when failing to relocate the purgatory
NFSv4.1: Fix the CREATE_SESSION slot number accounting
pNFS: Ensure LAYOUTGET and LAYOUTRETURN are properly serialised
nfsd: Close race between nfsd4_release_lockowner and nfsd4_lock
NFSv4.x: Fix a refcount leak in nfs_callback_up_net
pNFS: The client must not do I/O to the DS if it's lease has expired
kernfs: don't depend on d_find_any_alias() when generating notifications
powerpc/mm: Don't alias user region to other regions below PAGE_OFFSET
powerpc/powernv : Drop reference added by kset_find_obj()
powerpc/tm: do not use r13 for tabort_syscall
tipc: move linearization of buffers to generic code
lightnvm: put bio before return
fscrypto: require write access to mount to set encryption policy
Revert "KVM: x86: fix missed hardware breakpoints"
MIPS: KVM: Check for pfn noslot case
clocksource/drivers/sun4i: Clear interrupts after stopping timer in probe function
fscrypto: add authorization check for setting encryption policy
ext4: use __GFP_NOFAIL in ext4_free_blocks()
Conflicts:
arch/arm/kernel/devtree.c
arch/arm64/Kconfig
arch/arm64/kernel/arm64ksyms.c
arch/arm64/kernel/psci.c
arch/arm64/mm/fault.c
drivers/android/binder.c
drivers/usb/host/xhci-hub.c
fs/ext4/readpage.c
include/linux/mmc/core.h
include/linux/mmzone.h
mm/memcontrol.c
net/core/filter.c
net/netlink/af_netlink.c
net/netlink/af_netlink.h
Change-Id: I99fe7a0914e83e284b11b33185b71448a8999d1f
Signed-off-by: Runmin Wang <runminw@codeaurora.org>
Signed-off-by: Blagovest Kolenichev <bkolenichev@codeaurora.org>
2017-02-28 17:10:49 -08:00
|
|
|
binder_user_error("%d:%d got transaction with unaligned buffers size, %llu\n",
|
2016-09-30 14:10:07 +02:00
|
|
|
proc->pid, thread->pid,
|
|
|
|
(u64)extra_buffers_size);
|
|
|
|
return_error = BR_FAILED_REPLY;
|
2017-03-22 17:19:52 -07:00
|
|
|
return_error_param = -EINVAL;
|
|
|
|
return_error_line = __LINE__;
|
2016-09-30 14:10:07 +02:00
|
|
|
goto err_bad_offset;
|
|
|
|
}
|
|
|
|
off_end = (void *)off_start + tr->offsets_size;
|
|
|
|
sg_bufp = (u8 *)(PTR_ALIGN(off_end, sizeof(void *)));
|
|
|
|
sg_buf_end = sg_bufp + extra_buffers_size;
|
2015-11-09 13:08:12 -08:00
|
|
|
off_min = 0;
|
2011-11-30 20:18:14 +09:00
|
|
|
for (; offp < off_end; offp++) {
|
2016-07-13 12:06:49 +02:00
|
|
|
struct binder_object_header *hdr;
|
|
|
|
size_t object_size = binder_validate_object(t->buffer, *offp);
|
2014-05-01 01:30:23 +09:00
|
|
|
|
2016-07-13 12:06:49 +02:00
|
|
|
if (object_size == 0 || *offp < off_min) {
|
|
|
|
binder_user_error("%d:%d got transaction with invalid offset (%lld, min %lld max %lld) or object.\n",
|
2015-11-09 13:08:12 -08:00
|
|
|
proc->pid, thread->pid, (u64)*offp,
|
|
|
|
(u64)off_min,
|
2016-07-13 12:06:49 +02:00
|
|
|
(u64)t->buffer->data_size);
|
2011-11-30 20:18:14 +09:00
|
|
|
return_error = BR_FAILED_REPLY;
|
2017-03-22 17:19:52 -07:00
|
|
|
return_error_param = -EINVAL;
|
|
|
|
return_error_line = __LINE__;
|
2011-11-30 20:18:14 +09:00
|
|
|
goto err_bad_offset;
|
|
|
|
}
|
2016-07-13 12:06:49 +02:00
|
|
|
|
|
|
|
hdr = (struct binder_object_header *)(t->buffer->data + *offp);
|
|
|
|
off_min = *offp + object_size;
|
|
|
|
switch (hdr->type) {
|
2011-11-30 20:18:14 +09:00
|
|
|
case BINDER_TYPE_BINDER:
|
|
|
|
case BINDER_TYPE_WEAK_BINDER: {
|
2016-07-13 12:06:49 +02:00
|
|
|
struct flat_binder_object *fp;
|
2014-05-01 01:30:23 +09:00
|
|
|
|
2016-07-13 12:06:49 +02:00
|
|
|
fp = to_flat_binder_object(hdr);
|
2016-09-29 15:38:14 +02:00
|
|
|
ret = binder_translate_binder(fp, t, thread);
|
|
|
|
if (ret < 0) {
|
2011-11-30 20:18:14 +09:00
|
|
|
return_error = BR_FAILED_REPLY;
|
2017-03-22 17:19:52 -07:00
|
|
|
return_error_param = ret;
|
|
|
|
return_error_line = __LINE__;
|
2016-09-29 15:38:14 +02:00
|
|
|
goto err_translate_failed;
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case BINDER_TYPE_HANDLE:
|
|
|
|
case BINDER_TYPE_WEAK_HANDLE: {
|
2016-07-13 12:06:49 +02:00
|
|
|
struct flat_binder_object *fp;
|
|
|
|
|
|
|
|
fp = to_flat_binder_object(hdr);
|
2016-09-29 15:38:14 +02:00
|
|
|
ret = binder_translate_handle(fp, t, thread);
|
|
|
|
if (ret < 0) {
|
2015-01-21 10:54:10 -05:00
|
|
|
return_error = BR_FAILED_REPLY;
|
2017-03-22 17:19:52 -07:00
|
|
|
return_error_param = ret;
|
|
|
|
return_error_line = __LINE__;
|
2016-09-29 15:38:14 +02:00
|
|
|
goto err_translate_failed;
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case BINDER_TYPE_FD: {
|
2016-07-13 12:06:49 +02:00
|
|
|
struct binder_fd_object *fp = to_binder_fd_object(hdr);
|
2016-09-29 15:38:14 +02:00
|
|
|
int target_fd = binder_translate_fd(fp->fd, t, thread,
|
|
|
|
in_reply_to);
|
2011-11-30 20:18:14 +09:00
|
|
|
|
|
|
|
if (target_fd < 0) {
|
|
|
|
return_error = BR_FAILED_REPLY;
|
2017-03-22 17:19:52 -07:00
|
|
|
return_error_param = target_fd;
|
|
|
|
return_error_line = __LINE__;
|
2016-09-29 15:38:14 +02:00
|
|
|
goto err_translate_failed;
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
2016-07-13 12:06:49 +02:00
|
|
|
fp->pad_binder = 0;
|
|
|
|
fp->fd = target_fd;
|
2011-11-30 20:18:14 +09:00
|
|
|
} break;
|
2016-10-18 13:58:55 +02:00
|
|
|
case BINDER_TYPE_FDA: {
|
|
|
|
struct binder_fd_array_object *fda =
|
|
|
|
to_binder_fd_array_object(hdr);
|
|
|
|
struct binder_buffer_object *parent =
|
|
|
|
binder_validate_ptr(t->buffer, fda->parent,
|
|
|
|
off_start,
|
|
|
|
offp - off_start);
|
|
|
|
if (!parent) {
|
|
|
|
binder_user_error("%d:%d got transaction with invalid parent offset or type\n",
|
|
|
|
proc->pid, thread->pid);
|
|
|
|
return_error = BR_FAILED_REPLY;
|
2017-03-22 17:19:52 -07:00
|
|
|
return_error_param = -EINVAL;
|
|
|
|
return_error_line = __LINE__;
|
2016-10-18 13:58:55 +02:00
|
|
|
goto err_bad_parent;
|
|
|
|
}
|
|
|
|
if (!binder_validate_fixup(t->buffer, off_start,
|
|
|
|
parent, fda->parent_offset,
|
|
|
|
last_fixup_obj,
|
|
|
|
last_fixup_min_off)) {
|
|
|
|
binder_user_error("%d:%d got transaction with out-of-order buffer fixup\n",
|
|
|
|
proc->pid, thread->pid);
|
|
|
|
return_error = BR_FAILED_REPLY;
|
2017-03-22 17:19:52 -07:00
|
|
|
return_error_param = -EINVAL;
|
|
|
|
return_error_line = __LINE__;
|
2016-10-18 13:58:55 +02:00
|
|
|
goto err_bad_parent;
|
|
|
|
}
|
|
|
|
ret = binder_translate_fd_array(fda, parent, t, thread,
|
|
|
|
in_reply_to);
|
|
|
|
if (ret < 0) {
|
|
|
|
return_error = BR_FAILED_REPLY;
|
2017-03-22 17:19:52 -07:00
|
|
|
return_error_param = ret;
|
|
|
|
return_error_line = __LINE__;
|
2016-10-18 13:58:55 +02:00
|
|
|
goto err_translate_failed;
|
|
|
|
}
|
|
|
|
last_fixup_obj = parent;
|
|
|
|
last_fixup_min_off =
|
|
|
|
fda->parent_offset + sizeof(u32) * fda->num_fds;
|
|
|
|
} break;
|
2016-09-30 14:10:07 +02:00
|
|
|
case BINDER_TYPE_PTR: {
|
|
|
|
struct binder_buffer_object *bp =
|
|
|
|
to_binder_buffer_object(hdr);
|
|
|
|
size_t buf_left = sg_buf_end - sg_bufp;
|
|
|
|
|
|
|
|
if (bp->length > buf_left) {
|
|
|
|
binder_user_error("%d:%d got transaction with too large buffer\n",
|
|
|
|
proc->pid, thread->pid);
|
|
|
|
return_error = BR_FAILED_REPLY;
|
2017-03-22 17:19:52 -07:00
|
|
|
return_error_param = -EINVAL;
|
|
|
|
return_error_line = __LINE__;
|
2016-09-30 14:10:07 +02:00
|
|
|
goto err_bad_offset;
|
|
|
|
}
|
2017-07-26 05:01:18 -07:00
|
|
|
if (copy_from_user(sg_bufp,
|
|
|
|
(const void __user *)(uintptr_t)
|
|
|
|
bp->buffer, bp->length)) {
|
2016-09-30 14:10:07 +02:00
|
|
|
binder_user_error("%d:%d got transaction with invalid offsets ptr\n",
|
|
|
|
proc->pid, thread->pid);
|
2017-03-22 17:19:52 -07:00
|
|
|
return_error_param = -EFAULT;
|
2016-09-30 14:10:07 +02:00
|
|
|
return_error = BR_FAILED_REPLY;
|
2017-03-22 17:19:52 -07:00
|
|
|
return_error_line = __LINE__;
|
2016-09-30 14:10:07 +02:00
|
|
|
goto err_copy_data_failed;
|
|
|
|
}
|
|
|
|
/* Fixup buffer pointer to target proc address space */
|
|
|
|
bp->buffer = (uintptr_t)sg_bufp +
|
2016-10-10 10:40:53 -07:00
|
|
|
binder_alloc_get_user_buffer_offset(
|
|
|
|
&target_proc->alloc);
|
2016-09-30 14:10:07 +02:00
|
|
|
sg_bufp += ALIGN(bp->length, sizeof(u64));
|
|
|
|
|
|
|
|
ret = binder_fixup_parent(t, thread, bp, off_start,
|
|
|
|
offp - off_start,
|
|
|
|
last_fixup_obj,
|
|
|
|
last_fixup_min_off);
|
|
|
|
if (ret < 0) {
|
|
|
|
return_error = BR_FAILED_REPLY;
|
2017-03-22 17:19:52 -07:00
|
|
|
return_error_param = ret;
|
|
|
|
return_error_line = __LINE__;
|
2016-09-30 14:10:07 +02:00
|
|
|
goto err_translate_failed;
|
|
|
|
}
|
|
|
|
last_fixup_obj = bp;
|
|
|
|
last_fixup_min_off = 0;
|
|
|
|
} break;
|
2011-11-30 20:18:14 +09:00
|
|
|
default:
|
2013-07-04 10:54:48 +01:00
|
|
|
binder_user_error("%d:%d got transaction with invalid object type, %x\n",
|
2016-07-13 12:06:49 +02:00
|
|
|
proc->pid, thread->pid, hdr->type);
|
2011-11-30 20:18:14 +09:00
|
|
|
return_error = BR_FAILED_REPLY;
|
2017-03-22 17:19:52 -07:00
|
|
|
return_error_param = -EINVAL;
|
|
|
|
return_error_line = __LINE__;
|
2011-11-30 20:18:14 +09:00
|
|
|
goto err_bad_object_type;
|
|
|
|
}
|
|
|
|
}
|
2017-05-09 08:31:32 -07:00
|
|
|
tcomplete->type = BINDER_WORK_TRANSACTION_COMPLETE;
|
2017-06-08 13:45:59 -07:00
|
|
|
t->work.type = BINDER_WORK_TRANSACTION;
|
2017-05-09 08:31:32 -07:00
|
|
|
|
2011-11-30 20:18:14 +09:00
|
|
|
if (reply) {
|
2017-10-19 15:04:46 +02:00
|
|
|
binder_enqueue_thread_work(thread, tcomplete);
|
2017-06-02 13:36:52 -07:00
|
|
|
binder_inner_proc_lock(target_proc);
|
|
|
|
if (target_thread->is_dead) {
|
|
|
|
binder_inner_proc_unlock(target_proc);
|
2017-05-12 14:42:55 -07:00
|
|
|
goto err_dead_proc_or_thread;
|
2017-06-02 13:36:52 -07:00
|
|
|
}
|
2011-11-30 20:18:14 +09:00
|
|
|
BUG_ON(t->buffer->async_transaction != 0);
|
2017-06-02 13:36:52 -07:00
|
|
|
binder_pop_transaction_ilocked(target_thread, in_reply_to);
|
2017-10-19 15:04:46 +02:00
|
|
|
binder_enqueue_thread_work_ilocked(target_thread, &t->work);
|
2017-06-02 13:36:52 -07:00
|
|
|
binder_inner_proc_unlock(target_proc);
|
2017-06-06 15:17:46 -07:00
|
|
|
wake_up_interruptible_sync(&target_thread->wait);
|
2017-05-26 10:48:56 -07:00
|
|
|
binder_restore_priority(current, in_reply_to->saved_priority);
|
2017-03-30 18:02:13 -07:00
|
|
|
binder_free_transaction(in_reply_to);
|
2011-11-30 20:18:14 +09:00
|
|
|
} else if (!(t->flags & TF_ONE_WAY)) {
|
|
|
|
BUG_ON(t->buffer->async_transaction != 0);
|
2017-06-02 13:36:52 -07:00
|
|
|
binder_inner_proc_lock(proc);
|
2017-11-13 09:55:21 +01:00
|
|
|
/*
|
|
|
|
* Defer the TRANSACTION_COMPLETE, so we don't return to
|
|
|
|
* userspace immediately; this allows the target process to
|
|
|
|
* immediately start processing this transaction, reducing
|
|
|
|
* latency. We will then return the TRANSACTION_COMPLETE when
|
|
|
|
* the target replies (or there is an error).
|
|
|
|
*/
|
|
|
|
binder_enqueue_deferred_thread_work_ilocked(thread, tcomplete);
|
2011-11-30 20:18:14 +09:00
|
|
|
t->need_reply = 1;
|
|
|
|
t->from_parent = thread->transaction_stack;
|
|
|
|
thread->transaction_stack = t;
|
2017-06-02 13:36:52 -07:00
|
|
|
binder_inner_proc_unlock(proc);
|
2017-06-06 15:17:46 -07:00
|
|
|
if (!binder_proc_transaction(t, target_proc, target_thread)) {
|
2017-06-02 13:36:52 -07:00
|
|
|
binder_inner_proc_lock(proc);
|
|
|
|
binder_pop_transaction_ilocked(thread, t);
|
|
|
|
binder_inner_proc_unlock(proc);
|
2017-05-12 14:42:55 -07:00
|
|
|
goto err_dead_proc_or_thread;
|
|
|
|
}
|
2011-11-30 20:18:14 +09:00
|
|
|
} else {
|
|
|
|
BUG_ON(target_node == NULL);
|
|
|
|
BUG_ON(t->buffer->async_transaction != 1);
|
2017-10-19 15:04:46 +02:00
|
|
|
binder_enqueue_thread_work(thread, tcomplete);
|
2017-06-06 15:17:46 -07:00
|
|
|
if (!binder_proc_transaction(t, target_proc, NULL))
|
2017-05-12 14:42:55 -07:00
|
|
|
goto err_dead_proc_or_thread;
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
2017-05-12 14:42:55 -07:00
|
|
|
if (target_thread)
|
|
|
|
binder_thread_dec_tmpref(target_thread);
|
|
|
|
binder_proc_dec_tmpref(target_proc);
|
2017-09-25 08:55:09 -07:00
|
|
|
if (target_node)
|
|
|
|
binder_dec_node_tmpref(target_node);
|
2017-05-24 13:33:28 -07:00
|
|
|
/*
|
|
|
|
* write barrier to synchronize with initialization
|
|
|
|
* of log entry
|
|
|
|
*/
|
|
|
|
smp_wmb();
|
|
|
|
WRITE_ONCE(e->debug_id_done, t_debug_id);
|
2011-11-30 20:18:14 +09:00
|
|
|
return;
|
|
|
|
|
2017-05-12 14:42:55 -07:00
|
|
|
err_dead_proc_or_thread:
|
|
|
|
return_error = BR_DEAD_REPLY;
|
|
|
|
return_error_line = __LINE__;
|
2017-05-22 11:26:23 -07:00
|
|
|
binder_dequeue_work(proc, tcomplete);
|
2016-09-29 15:38:14 +02:00
|
|
|
err_translate_failed:
|
2011-11-30 20:18:14 +09:00
|
|
|
err_bad_object_type:
|
|
|
|
err_bad_offset:
|
2016-10-18 13:58:55 +02:00
|
|
|
err_bad_parent:
|
2011-11-30 20:18:14 +09:00
|
|
|
err_copy_data_failed:
|
2012-10-16 15:29:53 -07:00
|
|
|
trace_binder_transaction_failed_buffer_release(t->buffer);
|
2011-11-30 20:18:14 +09:00
|
|
|
binder_transaction_buffer_release(target_proc, t->buffer, offp);
|
2017-09-25 08:55:09 -07:00
|
|
|
if (target_node)
|
|
|
|
binder_dec_node_tmpref(target_node);
|
2017-05-26 11:56:29 -07:00
|
|
|
target_node = NULL;
|
2011-11-30 20:18:14 +09:00
|
|
|
t->buffer->transaction = NULL;
|
2016-10-10 10:40:53 -07:00
|
|
|
binder_alloc_free_buf(&target_proc->alloc, t->buffer);
|
2011-11-30 20:18:14 +09:00
|
|
|
err_binder_alloc_buf_failed:
|
|
|
|
kfree(tcomplete);
|
|
|
|
binder_stats_deleted(BINDER_STAT_TRANSACTION_COMPLETE);
|
|
|
|
err_alloc_tcomplete_failed:
|
|
|
|
kfree(t);
|
|
|
|
binder_stats_deleted(BINDER_STAT_TRANSACTION);
|
|
|
|
err_alloc_t_failed:
|
|
|
|
err_bad_call_stack:
|
|
|
|
err_empty_call_stack:
|
|
|
|
err_dead_binder:
|
|
|
|
err_invalid_target_handle:
|
2017-05-12 14:42:55 -07:00
|
|
|
if (target_thread)
|
|
|
|
binder_thread_dec_tmpref(target_thread);
|
|
|
|
if (target_proc)
|
|
|
|
binder_proc_dec_tmpref(target_proc);
|
2017-09-25 08:55:09 -07:00
|
|
|
if (target_node) {
|
2017-05-26 11:56:29 -07:00
|
|
|
binder_dec_node(target_node, 1, 0);
|
2017-09-25 08:55:09 -07:00
|
|
|
binder_dec_node_tmpref(target_node);
|
|
|
|
}
|
2017-05-26 11:56:29 -07:00
|
|
|
|
2011-11-30 20:18:14 +09:00
|
|
|
binder_debug(BINDER_DEBUG_FAILED_TRANSACTION,
|
2017-03-22 17:19:52 -07:00
|
|
|
"%d:%d transaction failed %d/%d, size %lld-%lld line %d\n",
|
|
|
|
proc->pid, thread->pid, return_error, return_error_param,
|
|
|
|
(u64)tr->data_size, (u64)tr->offsets_size,
|
|
|
|
return_error_line);
|
2011-11-30 20:18:14 +09:00
|
|
|
|
|
|
|
{
|
|
|
|
struct binder_transaction_log_entry *fe;
|
2014-05-01 01:30:23 +09:00
|
|
|
|
2017-03-22 17:19:52 -07:00
|
|
|
e->return_error = return_error;
|
|
|
|
e->return_error_param = return_error_param;
|
|
|
|
e->return_error_line = return_error_line;
|
2017-03-24 15:53:53 -07:00
|
|
|
fe = binder_transaction_log_add(&binder_transaction_log_failed);
|
2011-11-30 20:18:14 +09:00
|
|
|
*fe = *e;
|
2017-05-24 13:33:28 -07:00
|
|
|
/*
|
|
|
|
* write barrier to synchronize with initialization
|
|
|
|
* of log entry
|
|
|
|
*/
|
|
|
|
smp_wmb();
|
|
|
|
WRITE_ONCE(e->debug_id_done, t_debug_id);
|
|
|
|
WRITE_ONCE(fe->debug_id_done, t_debug_id);
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
|
|
|
|
2017-04-21 17:35:12 -07:00
|
|
|
BUG_ON(thread->return_error.cmd != BR_OK);
|
2011-11-30 20:18:14 +09:00
|
|
|
if (in_reply_to) {
|
2017-05-26 10:48:56 -07:00
|
|
|
binder_restore_priority(current, in_reply_to->saved_priority);
|
2017-04-21 17:35:12 -07:00
|
|
|
thread->return_error.cmd = BR_TRANSACTION_COMPLETE;
|
2017-10-19 15:04:46 +02:00
|
|
|
binder_enqueue_thread_work(thread, &thread->return_error.work);
|
2011-11-30 20:18:14 +09:00
|
|
|
binder_send_failed_reply(in_reply_to, return_error);
|
2017-04-21 17:35:12 -07:00
|
|
|
} else {
|
|
|
|
thread->return_error.cmd = return_error;
|
2017-10-19 15:04:46 +02:00
|
|
|
binder_enqueue_thread_work(thread, &thread->return_error.work);
|
2017-04-21 17:35:12 -07:00
|
|
|
}
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
|
|
|
|
2013-09-02 08:18:40 +02:00
|
|
|
static int binder_thread_write(struct binder_proc *proc,
|
|
|
|
struct binder_thread *thread,
|
2014-02-21 14:40:26 -08:00
|
|
|
binder_uintptr_t binder_buffer, size_t size,
|
|
|
|
binder_size_t *consumed)
|
2011-11-30 20:18:14 +09:00
|
|
|
{
|
|
|
|
uint32_t cmd;
|
2016-09-30 15:51:48 +02:00
|
|
|
struct binder_context *context = proc->context;
|
2014-02-21 14:40:26 -08:00
|
|
|
void __user *buffer = (void __user *)(uintptr_t)binder_buffer;
|
2011-11-30 20:18:14 +09:00
|
|
|
void __user *ptr = buffer + *consumed;
|
|
|
|
void __user *end = buffer + size;
|
|
|
|
|
2017-04-21 17:35:12 -07:00
|
|
|
while (ptr < end && thread->return_error.cmd == BR_OK) {
|
2017-05-08 09:16:27 -07:00
|
|
|
int ret;
|
|
|
|
|
2017-07-26 05:01:18 -07:00
|
|
|
if (get_user(cmd, (uint32_t __user *)ptr))
|
2011-11-30 20:18:14 +09:00
|
|
|
return -EFAULT;
|
|
|
|
ptr += sizeof(uint32_t);
|
2012-10-16 15:29:53 -07:00
|
|
|
trace_binder_command(cmd);
|
2017-03-24 15:53:53 -07:00
|
|
|
if (_IOC_NR(cmd) < ARRAY_SIZE(binder_stats.bc)) {
|
2016-10-13 16:36:15 -07:00
|
|
|
atomic_inc(&binder_stats.bc[_IOC_NR(cmd)]);
|
|
|
|
atomic_inc(&proc->stats.bc[_IOC_NR(cmd)]);
|
|
|
|
atomic_inc(&thread->stats.bc[_IOC_NR(cmd)]);
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
|
|
|
switch (cmd) {
|
|
|
|
case BC_INCREFS:
|
|
|
|
case BC_ACQUIRE:
|
|
|
|
case BC_RELEASE:
|
|
|
|
case BC_DECREFS: {
|
|
|
|
uint32_t target;
|
|
|
|
const char *debug_string;
|
2017-05-08 09:16:27 -07:00
|
|
|
bool strong = cmd == BC_ACQUIRE || cmd == BC_RELEASE;
|
|
|
|
bool increment = cmd == BC_INCREFS || cmd == BC_ACQUIRE;
|
|
|
|
struct binder_ref_data rdata;
|
2011-11-30 20:18:14 +09:00
|
|
|
|
2017-07-26 05:01:18 -07:00
|
|
|
if (get_user(target, (uint32_t __user *)ptr))
|
2011-11-30 20:18:14 +09:00
|
|
|
return -EFAULT;
|
2016-10-17 12:33:15 -07:00
|
|
|
|
2011-11-30 20:18:14 +09:00
|
|
|
ptr += sizeof(uint32_t);
|
2017-05-08 09:16:27 -07:00
|
|
|
ret = -1;
|
|
|
|
if (increment && !target) {
|
2016-10-17 12:33:15 -07:00
|
|
|
struct binder_node *ctx_mgr_node;
|
|
|
|
mutex_lock(&context->context_mgr_node_lock);
|
|
|
|
ctx_mgr_node = context->binder_context_mgr_node;
|
2017-05-08 09:16:27 -07:00
|
|
|
if (ctx_mgr_node)
|
|
|
|
ret = binder_inc_ref_for_node(
|
|
|
|
proc, ctx_mgr_node,
|
|
|
|
strong, NULL, &rdata);
|
2016-10-17 12:33:15 -07:00
|
|
|
mutex_unlock(&context->context_mgr_node_lock);
|
|
|
|
}
|
2017-05-08 09:16:27 -07:00
|
|
|
if (ret)
|
|
|
|
ret = binder_update_ref_for_handle(
|
|
|
|
proc, target, increment, strong,
|
|
|
|
&rdata);
|
|
|
|
if (!ret && rdata.desc != target) {
|
|
|
|
binder_user_error("%d:%d tried to acquire reference to desc %d, got %d instead\n",
|
|
|
|
proc->pid, thread->pid,
|
|
|
|
target, rdata.desc);
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
|
|
|
switch (cmd) {
|
|
|
|
case BC_INCREFS:
|
|
|
|
debug_string = "IncRefs";
|
|
|
|
break;
|
|
|
|
case BC_ACQUIRE:
|
|
|
|
debug_string = "Acquire";
|
|
|
|
break;
|
|
|
|
case BC_RELEASE:
|
|
|
|
debug_string = "Release";
|
|
|
|
break;
|
|
|
|
case BC_DECREFS:
|
|
|
|
default:
|
|
|
|
debug_string = "DecRefs";
|
2017-05-08 09:16:27 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (ret) {
|
|
|
|
binder_user_error("%d:%d %s %d refcount change on invalid ref %d ret %d\n",
|
|
|
|
proc->pid, thread->pid, debug_string,
|
|
|
|
strong, target, ret);
|
2011-11-30 20:18:14 +09:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
binder_debug(BINDER_DEBUG_USER_REFS,
|
2017-05-08 09:16:27 -07:00
|
|
|
"%d:%d %s ref %d desc %d s %d w %d\n",
|
|
|
|
proc->pid, thread->pid, debug_string,
|
|
|
|
rdata.debug_id, rdata.desc, rdata.strong,
|
|
|
|
rdata.weak);
|
2011-11-30 20:18:14 +09:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case BC_INCREFS_DONE:
|
|
|
|
case BC_ACQUIRE_DONE: {
|
2014-02-21 14:40:26 -08:00
|
|
|
binder_uintptr_t node_ptr;
|
|
|
|
binder_uintptr_t cookie;
|
2011-11-30 20:18:14 +09:00
|
|
|
struct binder_node *node;
|
2017-06-08 13:45:59 -07:00
|
|
|
bool free_node;
|
2011-11-30 20:18:14 +09:00
|
|
|
|
2017-07-26 05:01:18 -07:00
|
|
|
if (get_user(node_ptr, (binder_uintptr_t __user *)ptr))
|
2011-11-30 20:18:14 +09:00
|
|
|
return -EFAULT;
|
2014-02-21 14:40:26 -08:00
|
|
|
ptr += sizeof(binder_uintptr_t);
|
2017-07-26 05:01:18 -07:00
|
|
|
if (get_user(cookie, (binder_uintptr_t __user *)ptr))
|
2011-11-30 20:18:14 +09:00
|
|
|
return -EFAULT;
|
2014-02-21 14:40:26 -08:00
|
|
|
ptr += sizeof(binder_uintptr_t);
|
2011-11-30 20:18:14 +09:00
|
|
|
node = binder_get_node(proc, node_ptr);
|
|
|
|
if (node == NULL) {
|
2014-02-21 14:40:26 -08:00
|
|
|
binder_user_error("%d:%d %s u%016llx no match\n",
|
2011-11-30 20:18:14 +09:00
|
|
|
proc->pid, thread->pid,
|
|
|
|
cmd == BC_INCREFS_DONE ?
|
|
|
|
"BC_INCREFS_DONE" :
|
|
|
|
"BC_ACQUIRE_DONE",
|
2014-02-21 14:40:26 -08:00
|
|
|
(u64)node_ptr);
|
2011-11-30 20:18:14 +09:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (cookie != node->cookie) {
|
2014-02-21 14:40:26 -08:00
|
|
|
binder_user_error("%d:%d %s u%016llx node %d cookie mismatch %016llx != %016llx\n",
|
2011-11-30 20:18:14 +09:00
|
|
|
proc->pid, thread->pid,
|
|
|
|
cmd == BC_INCREFS_DONE ?
|
|
|
|
"BC_INCREFS_DONE" : "BC_ACQUIRE_DONE",
|
2014-02-21 14:40:26 -08:00
|
|
|
(u64)node_ptr, node->debug_id,
|
|
|
|
(u64)cookie, (u64)node->cookie);
|
2017-05-09 11:08:05 -07:00
|
|
|
binder_put_node(node);
|
2011-11-30 20:18:14 +09:00
|
|
|
break;
|
|
|
|
}
|
2017-06-08 13:45:59 -07:00
|
|
|
binder_node_inner_lock(node);
|
2011-11-30 20:18:14 +09:00
|
|
|
if (cmd == BC_ACQUIRE_DONE) {
|
|
|
|
if (node->pending_strong_ref == 0) {
|
2012-10-30 22:35:43 +05:30
|
|
|
binder_user_error("%d:%d BC_ACQUIRE_DONE node %d has no pending acquire request\n",
|
2011-11-30 20:18:14 +09:00
|
|
|
proc->pid, thread->pid,
|
|
|
|
node->debug_id);
|
2017-06-08 13:45:59 -07:00
|
|
|
binder_node_inner_unlock(node);
|
2017-05-09 11:08:05 -07:00
|
|
|
binder_put_node(node);
|
2011-11-30 20:18:14 +09:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
node->pending_strong_ref = 0;
|
|
|
|
} else {
|
|
|
|
if (node->pending_weak_ref == 0) {
|
2012-10-30 22:35:43 +05:30
|
|
|
binder_user_error("%d:%d BC_INCREFS_DONE node %d has no pending increfs request\n",
|
2011-11-30 20:18:14 +09:00
|
|
|
proc->pid, thread->pid,
|
|
|
|
node->debug_id);
|
2017-06-08 13:45:59 -07:00
|
|
|
binder_node_inner_unlock(node);
|
2017-05-09 11:08:05 -07:00
|
|
|
binder_put_node(node);
|
2011-11-30 20:18:14 +09:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
node->pending_weak_ref = 0;
|
|
|
|
}
|
2017-06-08 13:45:59 -07:00
|
|
|
free_node = binder_dec_node_nilocked(node,
|
|
|
|
cmd == BC_ACQUIRE_DONE, 0);
|
|
|
|
WARN_ON(free_node);
|
2011-11-30 20:18:14 +09:00
|
|
|
binder_debug(BINDER_DEBUG_USER_REFS,
|
2017-05-09 11:08:05 -07:00
|
|
|
"%d:%d %s node %d ls %d lw %d tr %d\n",
|
2011-11-30 20:18:14 +09:00
|
|
|
proc->pid, thread->pid,
|
|
|
|
cmd == BC_INCREFS_DONE ? "BC_INCREFS_DONE" : "BC_ACQUIRE_DONE",
|
2017-05-09 11:08:05 -07:00
|
|
|
node->debug_id, node->local_strong_refs,
|
|
|
|
node->local_weak_refs, node->tmp_refs);
|
2017-06-08 13:45:59 -07:00
|
|
|
binder_node_inner_unlock(node);
|
2017-05-09 11:08:05 -07:00
|
|
|
binder_put_node(node);
|
2011-11-30 20:18:14 +09:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case BC_ATTEMPT_ACQUIRE:
|
2012-10-30 22:35:43 +05:30
|
|
|
pr_err("BC_ATTEMPT_ACQUIRE not supported\n");
|
2011-11-30 20:18:14 +09:00
|
|
|
return -EINVAL;
|
|
|
|
case BC_ACQUIRE_RESULT:
|
2012-10-30 22:35:43 +05:30
|
|
|
pr_err("BC_ACQUIRE_RESULT not supported\n");
|
2011-11-30 20:18:14 +09:00
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
case BC_FREE_BUFFER: {
|
2014-02-21 14:40:26 -08:00
|
|
|
binder_uintptr_t data_ptr;
|
2011-11-30 20:18:14 +09:00
|
|
|
struct binder_buffer *buffer;
|
|
|
|
|
2017-07-26 05:01:18 -07:00
|
|
|
if (get_user(data_ptr, (binder_uintptr_t __user *)ptr))
|
2011-11-30 20:18:14 +09:00
|
|
|
return -EFAULT;
|
2014-02-21 14:40:26 -08:00
|
|
|
ptr += sizeof(binder_uintptr_t);
|
2011-11-30 20:18:14 +09:00
|
|
|
|
2017-04-21 14:32:11 -07:00
|
|
|
buffer = binder_alloc_prepare_to_free(&proc->alloc,
|
|
|
|
data_ptr);
|
2011-11-30 20:18:14 +09:00
|
|
|
if (buffer == NULL) {
|
2014-02-21 14:40:26 -08:00
|
|
|
binder_user_error("%d:%d BC_FREE_BUFFER u%016llx no match\n",
|
|
|
|
proc->pid, thread->pid, (u64)data_ptr);
|
2011-11-30 20:18:14 +09:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!buffer->allow_user_free) {
|
2014-02-21 14:40:26 -08:00
|
|
|
binder_user_error("%d:%d BC_FREE_BUFFER u%016llx matched unreturned buffer\n",
|
|
|
|
proc->pid, thread->pid, (u64)data_ptr);
|
2011-11-30 20:18:14 +09:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
binder_debug(BINDER_DEBUG_FREE_BUFFER,
|
2014-02-21 14:40:26 -08:00
|
|
|
"%d:%d BC_FREE_BUFFER u%016llx found buffer %d for %s transaction\n",
|
|
|
|
proc->pid, thread->pid, (u64)data_ptr,
|
|
|
|
buffer->debug_id,
|
2011-11-30 20:18:14 +09:00
|
|
|
buffer->transaction ? "active" : "finished");
|
|
|
|
|
|
|
|
if (buffer->transaction) {
|
|
|
|
buffer->transaction->buffer = NULL;
|
|
|
|
buffer->transaction = NULL;
|
|
|
|
}
|
|
|
|
if (buffer->async_transaction && buffer->target_node) {
|
2016-10-20 10:33:00 -07:00
|
|
|
struct binder_node *buf_node;
|
|
|
|
struct binder_work *w;
|
|
|
|
|
|
|
|
buf_node = buffer->target_node;
|
2017-06-08 13:45:59 -07:00
|
|
|
binder_node_inner_lock(buf_node);
|
2016-10-20 10:33:00 -07:00
|
|
|
BUG_ON(!buf_node->has_async_transaction);
|
|
|
|
BUG_ON(buf_node->proc != proc);
|
|
|
|
w = binder_dequeue_work_head_ilocked(
|
|
|
|
&buf_node->async_todo);
|
2017-08-10 13:56:16 +02:00
|
|
|
if (!w) {
|
2016-10-20 10:33:00 -07:00
|
|
|
buf_node->has_async_transaction = 0;
|
2017-08-10 13:56:16 +02:00
|
|
|
} else {
|
2016-10-20 10:33:00 -07:00
|
|
|
binder_enqueue_work_ilocked(
|
2017-08-10 13:56:16 +02:00
|
|
|
w, &proc->todo);
|
|
|
|
binder_wakeup_proc_ilocked(proc);
|
|
|
|
}
|
2017-06-08 13:45:59 -07:00
|
|
|
binder_node_inner_unlock(buf_node);
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
2012-10-16 15:29:53 -07:00
|
|
|
trace_binder_transaction_buffer_release(buffer);
|
2011-11-30 20:18:14 +09:00
|
|
|
binder_transaction_buffer_release(proc, buffer, NULL);
|
2016-10-10 10:40:53 -07:00
|
|
|
binder_alloc_free_buf(&proc->alloc, buffer);
|
2011-11-30 20:18:14 +09:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-09-30 14:10:07 +02:00
|
|
|
case BC_TRANSACTION_SG:
|
|
|
|
case BC_REPLY_SG: {
|
|
|
|
struct binder_transaction_data_sg tr;
|
|
|
|
|
2017-07-26 05:01:18 -07:00
|
|
|
if (copy_from_user(&tr, ptr, sizeof(tr)))
|
2016-09-30 14:10:07 +02:00
|
|
|
return -EFAULT;
|
|
|
|
ptr += sizeof(tr);
|
|
|
|
binder_transaction(proc, thread, &tr.transaction_data,
|
|
|
|
cmd == BC_REPLY_SG, tr.buffers_size);
|
|
|
|
break;
|
|
|
|
}
|
2011-11-30 20:18:14 +09:00
|
|
|
case BC_TRANSACTION:
|
|
|
|
case BC_REPLY: {
|
|
|
|
struct binder_transaction_data tr;
|
|
|
|
|
2017-07-26 05:01:18 -07:00
|
|
|
if (copy_from_user(&tr, ptr, sizeof(tr)))
|
2011-11-30 20:18:14 +09:00
|
|
|
return -EFAULT;
|
|
|
|
ptr += sizeof(tr);
|
2016-09-30 14:05:40 +02:00
|
|
|
binder_transaction(proc, thread, &tr,
|
|
|
|
cmd == BC_REPLY, 0);
|
2011-11-30 20:18:14 +09:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case BC_REGISTER_LOOPER:
|
|
|
|
binder_debug(BINDER_DEBUG_THREADS,
|
2012-10-30 22:35:43 +05:30
|
|
|
"%d:%d BC_REGISTER_LOOPER\n",
|
2011-11-30 20:18:14 +09:00
|
|
|
proc->pid, thread->pid);
|
2017-05-25 17:35:02 -07:00
|
|
|
binder_inner_proc_lock(proc);
|
2011-11-30 20:18:14 +09:00
|
|
|
if (thread->looper & BINDER_LOOPER_STATE_ENTERED) {
|
|
|
|
thread->looper |= BINDER_LOOPER_STATE_INVALID;
|
2012-10-30 22:35:43 +05:30
|
|
|
binder_user_error("%d:%d ERROR: BC_REGISTER_LOOPER called after BC_ENTER_LOOPER\n",
|
2011-11-30 20:18:14 +09:00
|
|
|
proc->pid, thread->pid);
|
|
|
|
} else if (proc->requested_threads == 0) {
|
|
|
|
thread->looper |= BINDER_LOOPER_STATE_INVALID;
|
2012-10-30 22:35:43 +05:30
|
|
|
binder_user_error("%d:%d ERROR: BC_REGISTER_LOOPER called without request\n",
|
2011-11-30 20:18:14 +09:00
|
|
|
proc->pid, thread->pid);
|
|
|
|
} else {
|
|
|
|
proc->requested_threads--;
|
|
|
|
proc->requested_threads_started++;
|
|
|
|
}
|
|
|
|
thread->looper |= BINDER_LOOPER_STATE_REGISTERED;
|
2017-05-25 17:35:02 -07:00
|
|
|
binder_inner_proc_unlock(proc);
|
2011-11-30 20:18:14 +09:00
|
|
|
break;
|
|
|
|
case BC_ENTER_LOOPER:
|
|
|
|
binder_debug(BINDER_DEBUG_THREADS,
|
2012-10-30 22:35:43 +05:30
|
|
|
"%d:%d BC_ENTER_LOOPER\n",
|
2011-11-30 20:18:14 +09:00
|
|
|
proc->pid, thread->pid);
|
|
|
|
if (thread->looper & BINDER_LOOPER_STATE_REGISTERED) {
|
|
|
|
thread->looper |= BINDER_LOOPER_STATE_INVALID;
|
2012-10-30 22:35:43 +05:30
|
|
|
binder_user_error("%d:%d ERROR: BC_ENTER_LOOPER called after BC_REGISTER_LOOPER\n",
|
2011-11-30 20:18:14 +09:00
|
|
|
proc->pid, thread->pid);
|
|
|
|
}
|
|
|
|
thread->looper |= BINDER_LOOPER_STATE_ENTERED;
|
|
|
|
break;
|
|
|
|
case BC_EXIT_LOOPER:
|
|
|
|
binder_debug(BINDER_DEBUG_THREADS,
|
2012-10-30 22:35:43 +05:30
|
|
|
"%d:%d BC_EXIT_LOOPER\n",
|
2011-11-30 20:18:14 +09:00
|
|
|
proc->pid, thread->pid);
|
|
|
|
thread->looper |= BINDER_LOOPER_STATE_EXITED;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BC_REQUEST_DEATH_NOTIFICATION:
|
|
|
|
case BC_CLEAR_DEATH_NOTIFICATION: {
|
|
|
|
uint32_t target;
|
2014-02-21 14:40:26 -08:00
|
|
|
binder_uintptr_t cookie;
|
2011-11-30 20:18:14 +09:00
|
|
|
struct binder_ref *ref;
|
2016-10-20 16:43:34 -07:00
|
|
|
struct binder_ref_death *death = NULL;
|
2011-11-30 20:18:14 +09:00
|
|
|
|
2017-07-26 05:01:18 -07:00
|
|
|
if (get_user(target, (uint32_t __user *)ptr))
|
2011-11-30 20:18:14 +09:00
|
|
|
return -EFAULT;
|
|
|
|
ptr += sizeof(uint32_t);
|
2017-07-26 05:01:18 -07:00
|
|
|
if (get_user(cookie, (binder_uintptr_t __user *)ptr))
|
2011-11-30 20:18:14 +09:00
|
|
|
return -EFAULT;
|
2014-02-21 14:40:26 -08:00
|
|
|
ptr += sizeof(binder_uintptr_t);
|
2016-10-20 16:43:34 -07:00
|
|
|
if (cmd == BC_REQUEST_DEATH_NOTIFICATION) {
|
|
|
|
/*
|
|
|
|
* Allocate memory for death notification
|
|
|
|
* before taking lock
|
|
|
|
*/
|
|
|
|
death = kzalloc(sizeof(*death), GFP_KERNEL);
|
|
|
|
if (death == NULL) {
|
|
|
|
WARN_ON(thread->return_error.cmd !=
|
|
|
|
BR_OK);
|
|
|
|
thread->return_error.cmd = BR_ERROR;
|
2017-10-19 15:04:46 +02:00
|
|
|
binder_enqueue_thread_work(
|
|
|
|
thread,
|
|
|
|
&thread->return_error.work);
|
2016-10-20 16:43:34 -07:00
|
|
|
binder_debug(
|
|
|
|
BINDER_DEBUG_FAILED_TRANSACTION,
|
|
|
|
"%d:%d BC_REQUEST_DEATH_NOTIFICATION failed\n",
|
|
|
|
proc->pid, thread->pid);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
binder_proc_lock(proc);
|
|
|
|
ref = binder_get_ref_olocked(proc, target, false);
|
2011-11-30 20:18:14 +09:00
|
|
|
if (ref == NULL) {
|
2012-10-30 22:35:43 +05:30
|
|
|
binder_user_error("%d:%d %s invalid ref %d\n",
|
2011-11-30 20:18:14 +09:00
|
|
|
proc->pid, thread->pid,
|
|
|
|
cmd == BC_REQUEST_DEATH_NOTIFICATION ?
|
|
|
|
"BC_REQUEST_DEATH_NOTIFICATION" :
|
|
|
|
"BC_CLEAR_DEATH_NOTIFICATION",
|
|
|
|
target);
|
2016-10-20 16:43:34 -07:00
|
|
|
binder_proc_unlock(proc);
|
|
|
|
kfree(death);
|
2011-11-30 20:18:14 +09:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
binder_debug(BINDER_DEBUG_DEATH_NOTIFICATION,
|
2014-02-21 14:40:26 -08:00
|
|
|
"%d:%d %s %016llx ref %d desc %d s %d w %d for node %d\n",
|
2011-11-30 20:18:14 +09:00
|
|
|
proc->pid, thread->pid,
|
|
|
|
cmd == BC_REQUEST_DEATH_NOTIFICATION ?
|
|
|
|
"BC_REQUEST_DEATH_NOTIFICATION" :
|
|
|
|
"BC_CLEAR_DEATH_NOTIFICATION",
|
2017-05-08 09:16:27 -07:00
|
|
|
(u64)cookie, ref->data.debug_id,
|
|
|
|
ref->data.desc, ref->data.strong,
|
|
|
|
ref->data.weak, ref->node->debug_id);
|
2011-11-30 20:18:14 +09:00
|
|
|
|
2017-05-22 11:26:23 -07:00
|
|
|
binder_node_lock(ref->node);
|
2011-11-30 20:18:14 +09:00
|
|
|
if (cmd == BC_REQUEST_DEATH_NOTIFICATION) {
|
|
|
|
if (ref->death) {
|
2012-10-30 22:35:43 +05:30
|
|
|
binder_user_error("%d:%d BC_REQUEST_DEATH_NOTIFICATION death notification already set\n",
|
2011-11-30 20:18:14 +09:00
|
|
|
proc->pid, thread->pid);
|
2017-05-22 11:26:23 -07:00
|
|
|
binder_node_unlock(ref->node);
|
2016-10-20 16:43:34 -07:00
|
|
|
binder_proc_unlock(proc);
|
|
|
|
kfree(death);
|
2011-11-30 20:18:14 +09:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
binder_stats_created(BINDER_STAT_DEATH);
|
|
|
|
INIT_LIST_HEAD(&death->work.entry);
|
|
|
|
death->cookie = cookie;
|
|
|
|
ref->death = death;
|
|
|
|
if (ref->node->proc == NULL) {
|
|
|
|
ref->death->work.type = BINDER_WORK_DEAD_BINDER;
|
2017-08-10 13:50:52 +02:00
|
|
|
|
|
|
|
binder_inner_proc_lock(proc);
|
|
|
|
binder_enqueue_work_ilocked(
|
|
|
|
&ref->death->work, &proc->todo);
|
|
|
|
binder_wakeup_proc_ilocked(proc);
|
|
|
|
binder_inner_proc_unlock(proc);
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (ref->death == NULL) {
|
2012-10-30 22:35:43 +05:30
|
|
|
binder_user_error("%d:%d BC_CLEAR_DEATH_NOTIFICATION death notification not active\n",
|
2011-11-30 20:18:14 +09:00
|
|
|
proc->pid, thread->pid);
|
2017-06-08 13:45:59 -07:00
|
|
|
binder_node_unlock(ref->node);
|
2016-10-20 16:43:34 -07:00
|
|
|
binder_proc_unlock(proc);
|
2011-11-30 20:18:14 +09:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
death = ref->death;
|
|
|
|
if (death->cookie != cookie) {
|
2014-02-21 14:40:26 -08:00
|
|
|
binder_user_error("%d:%d BC_CLEAR_DEATH_NOTIFICATION death notification cookie mismatch %016llx != %016llx\n",
|
2011-11-30 20:18:14 +09:00
|
|
|
proc->pid, thread->pid,
|
2014-02-21 14:40:26 -08:00
|
|
|
(u64)death->cookie,
|
|
|
|
(u64)cookie);
|
2017-06-08 13:45:59 -07:00
|
|
|
binder_node_unlock(ref->node);
|
2016-10-20 16:43:34 -07:00
|
|
|
binder_proc_unlock(proc);
|
2011-11-30 20:18:14 +09:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
ref->death = NULL;
|
2016-10-20 10:33:00 -07:00
|
|
|
binder_inner_proc_lock(proc);
|
2011-11-30 20:18:14 +09:00
|
|
|
if (list_empty(&death->work.entry)) {
|
|
|
|
death->work.type = BINDER_WORK_CLEAR_DEATH_NOTIFICATION;
|
2016-10-20 10:33:00 -07:00
|
|
|
if (thread->looper &
|
|
|
|
(BINDER_LOOPER_STATE_REGISTERED |
|
|
|
|
BINDER_LOOPER_STATE_ENTERED))
|
2017-10-19 15:04:46 +02:00
|
|
|
binder_enqueue_thread_work_ilocked(
|
|
|
|
thread,
|
|
|
|
&death->work);
|
2016-10-20 10:33:00 -07:00
|
|
|
else {
|
|
|
|
binder_enqueue_work_ilocked(
|
|
|
|
&death->work,
|
|
|
|
&proc->todo);
|
2017-06-02 11:15:44 -07:00
|
|
|
binder_wakeup_proc_ilocked(
|
2017-06-06 15:17:46 -07:00
|
|
|
proc);
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
BUG_ON(death->work.type != BINDER_WORK_DEAD_BINDER);
|
|
|
|
death->work.type = BINDER_WORK_DEAD_BINDER_AND_CLEAR;
|
|
|
|
}
|
2016-10-20 10:33:00 -07:00
|
|
|
binder_inner_proc_unlock(proc);
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
2017-05-22 11:26:23 -07:00
|
|
|
binder_node_unlock(ref->node);
|
2016-10-20 16:43:34 -07:00
|
|
|
binder_proc_unlock(proc);
|
2011-11-30 20:18:14 +09:00
|
|
|
} break;
|
|
|
|
case BC_DEAD_BINDER_DONE: {
|
|
|
|
struct binder_work *w;
|
2014-02-21 14:40:26 -08:00
|
|
|
binder_uintptr_t cookie;
|
2011-11-30 20:18:14 +09:00
|
|
|
struct binder_ref_death *death = NULL;
|
2017-07-26 05:01:18 -07:00
|
|
|
|
|
|
|
if (get_user(cookie, (binder_uintptr_t __user *)ptr))
|
2011-11-30 20:18:14 +09:00
|
|
|
return -EFAULT;
|
|
|
|
|
2016-02-17 09:32:52 +08:00
|
|
|
ptr += sizeof(cookie);
|
2016-10-20 10:33:00 -07:00
|
|
|
binder_inner_proc_lock(proc);
|
|
|
|
list_for_each_entry(w, &proc->delivered_death,
|
|
|
|
entry) {
|
|
|
|
struct binder_ref_death *tmp_death =
|
|
|
|
container_of(w,
|
|
|
|
struct binder_ref_death,
|
|
|
|
work);
|
2014-05-01 01:30:23 +09:00
|
|
|
|
2011-11-30 20:18:14 +09:00
|
|
|
if (tmp_death->cookie == cookie) {
|
|
|
|
death = tmp_death;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
binder_debug(BINDER_DEBUG_DEAD_BINDER,
|
2014-02-21 14:40:26 -08:00
|
|
|
"%d:%d BC_DEAD_BINDER_DONE %016llx found %p\n",
|
|
|
|
proc->pid, thread->pid, (u64)cookie,
|
|
|
|
death);
|
2011-11-30 20:18:14 +09:00
|
|
|
if (death == NULL) {
|
2014-02-21 14:40:26 -08:00
|
|
|
binder_user_error("%d:%d BC_DEAD_BINDER_DONE %016llx not found\n",
|
|
|
|
proc->pid, thread->pid, (u64)cookie);
|
2016-10-20 10:33:00 -07:00
|
|
|
binder_inner_proc_unlock(proc);
|
2011-11-30 20:18:14 +09:00
|
|
|
break;
|
|
|
|
}
|
2016-10-20 10:33:00 -07:00
|
|
|
binder_dequeue_work_ilocked(&death->work);
|
2011-11-30 20:18:14 +09:00
|
|
|
if (death->work.type == BINDER_WORK_DEAD_BINDER_AND_CLEAR) {
|
|
|
|
death->work.type = BINDER_WORK_CLEAR_DEATH_NOTIFICATION;
|
2016-10-20 10:33:00 -07:00
|
|
|
if (thread->looper &
|
|
|
|
(BINDER_LOOPER_STATE_REGISTERED |
|
|
|
|
BINDER_LOOPER_STATE_ENTERED))
|
2017-10-19 15:04:46 +02:00
|
|
|
binder_enqueue_thread_work_ilocked(
|
|
|
|
thread, &death->work);
|
2016-10-20 10:33:00 -07:00
|
|
|
else {
|
|
|
|
binder_enqueue_work_ilocked(
|
|
|
|
&death->work,
|
|
|
|
&proc->todo);
|
2017-06-06 15:17:46 -07:00
|
|
|
binder_wakeup_proc_ilocked(proc);
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
|
|
|
}
|
2016-10-20 10:33:00 -07:00
|
|
|
binder_inner_proc_unlock(proc);
|
2017-07-26 05:01:18 -07:00
|
|
|
} break;
|
2011-11-30 20:18:14 +09:00
|
|
|
|
|
|
|
default:
|
2012-10-30 22:35:43 +05:30
|
|
|
pr_err("%d:%d unknown command %d\n",
|
2011-11-30 20:18:14 +09:00
|
|
|
proc->pid, thread->pid, cmd);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
*consumed = ptr - buffer;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-09-02 08:18:40 +02:00
|
|
|
static void binder_stat_br(struct binder_proc *proc,
|
|
|
|
struct binder_thread *thread, uint32_t cmd)
|
2011-11-30 20:18:14 +09:00
|
|
|
{
|
2012-10-16 15:29:53 -07:00
|
|
|
trace_binder_return(cmd);
|
2017-03-24 15:53:53 -07:00
|
|
|
if (_IOC_NR(cmd) < ARRAY_SIZE(binder_stats.br)) {
|
2016-10-13 16:36:15 -07:00
|
|
|
atomic_inc(&binder_stats.br[_IOC_NR(cmd)]);
|
|
|
|
atomic_inc(&proc->stats.br[_IOC_NR(cmd)]);
|
|
|
|
atomic_inc(&thread->stats.br[_IOC_NR(cmd)]);
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-24 10:51:01 -07:00
|
|
|
static int binder_put_node_cmd(struct binder_proc *proc,
|
|
|
|
struct binder_thread *thread,
|
|
|
|
void __user **ptrp,
|
|
|
|
binder_uintptr_t node_ptr,
|
|
|
|
binder_uintptr_t node_cookie,
|
|
|
|
int node_debug_id,
|
|
|
|
uint32_t cmd, const char *cmd_name)
|
|
|
|
{
|
|
|
|
void __user *ptr = *ptrp;
|
|
|
|
|
|
|
|
if (put_user(cmd, (uint32_t __user *)ptr))
|
|
|
|
return -EFAULT;
|
|
|
|
ptr += sizeof(uint32_t);
|
|
|
|
|
|
|
|
if (put_user(node_ptr, (binder_uintptr_t __user *)ptr))
|
|
|
|
return -EFAULT;
|
|
|
|
ptr += sizeof(binder_uintptr_t);
|
|
|
|
|
|
|
|
if (put_user(node_cookie, (binder_uintptr_t __user *)ptr))
|
|
|
|
return -EFAULT;
|
|
|
|
ptr += sizeof(binder_uintptr_t);
|
|
|
|
|
|
|
|
binder_stat_br(proc, thread, cmd);
|
|
|
|
binder_debug(BINDER_DEBUG_USER_REFS, "%d:%d %s %d u%016llx c%016llx\n",
|
|
|
|
proc->pid, thread->pid, cmd_name, node_debug_id,
|
|
|
|
(u64)node_ptr, (u64)node_cookie);
|
|
|
|
|
|
|
|
*ptrp = ptr;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-06-02 11:15:44 -07:00
|
|
|
static int binder_wait_for_work(struct binder_thread *thread,
|
|
|
|
bool do_proc_work)
|
2011-11-30 20:18:14 +09:00
|
|
|
{
|
2017-06-02 11:15:44 -07:00
|
|
|
DEFINE_WAIT(wait);
|
|
|
|
struct binder_proc *proc = thread->proc;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
freezer_do_not_count();
|
|
|
|
binder_inner_proc_lock(proc);
|
|
|
|
for (;;) {
|
|
|
|
prepare_to_wait(&thread->wait, &wait, TASK_INTERRUPTIBLE);
|
|
|
|
if (binder_has_work_ilocked(thread, do_proc_work))
|
|
|
|
break;
|
|
|
|
if (do_proc_work)
|
|
|
|
list_add(&thread->waiting_thread_node,
|
|
|
|
&proc->waiting_threads);
|
|
|
|
binder_inner_proc_unlock(proc);
|
|
|
|
schedule();
|
|
|
|
binder_inner_proc_lock(proc);
|
|
|
|
list_del_init(&thread->waiting_thread_node);
|
|
|
|
if (signal_pending(current)) {
|
|
|
|
ret = -ERESTARTSYS;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
finish_wait(&thread->wait, &wait);
|
|
|
|
binder_inner_proc_unlock(proc);
|
|
|
|
freezer_count();
|
|
|
|
|
|
|
|
return ret;
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
static int binder_thread_read(struct binder_proc *proc,
|
|
|
|
struct binder_thread *thread,
|
2014-02-21 14:40:26 -08:00
|
|
|
binder_uintptr_t binder_buffer, size_t size,
|
|
|
|
binder_size_t *consumed, int non_block)
|
2011-11-30 20:18:14 +09:00
|
|
|
{
|
2014-02-21 14:40:26 -08:00
|
|
|
void __user *buffer = (void __user *)(uintptr_t)binder_buffer;
|
2011-11-30 20:18:14 +09:00
|
|
|
void __user *ptr = buffer + *consumed;
|
|
|
|
void __user *end = buffer + size;
|
|
|
|
|
|
|
|
int ret = 0;
|
|
|
|
int wait_for_proc_work;
|
|
|
|
|
|
|
|
if (*consumed == 0) {
|
2017-07-26 05:01:18 -07:00
|
|
|
if (put_user(BR_NOOP, (uint32_t __user *)ptr))
|
2011-11-30 20:18:14 +09:00
|
|
|
return -EFAULT;
|
|
|
|
ptr += sizeof(uint32_t);
|
|
|
|
}
|
|
|
|
|
|
|
|
retry:
|
2017-06-02 13:36:52 -07:00
|
|
|
binder_inner_proc_lock(proc);
|
2017-06-02 11:15:44 -07:00
|
|
|
wait_for_proc_work = binder_available_for_proc_work_ilocked(thread);
|
2017-06-02 13:36:52 -07:00
|
|
|
binder_inner_proc_unlock(proc);
|
2011-11-30 20:18:14 +09:00
|
|
|
|
|
|
|
thread->looper |= BINDER_LOOPER_STATE_WAITING;
|
2012-10-16 15:29:53 -07:00
|
|
|
|
|
|
|
trace_binder_wait_for_work(wait_for_proc_work,
|
|
|
|
!!thread->transaction_stack,
|
2016-10-20 10:33:00 -07:00
|
|
|
!binder_worklist_empty(proc, &thread->todo));
|
2011-11-30 20:18:14 +09:00
|
|
|
if (wait_for_proc_work) {
|
|
|
|
if (!(thread->looper & (BINDER_LOOPER_STATE_REGISTERED |
|
|
|
|
BINDER_LOOPER_STATE_ENTERED))) {
|
2012-10-30 22:35:43 +05:30
|
|
|
binder_user_error("%d:%d ERROR: Thread waiting for process work before calling BC_REGISTER_LOOPER or BC_ENTER_LOOPER (state %x)\n",
|
2011-11-30 20:18:14 +09:00
|
|
|
proc->pid, thread->pid, thread->looper);
|
|
|
|
wait_event_interruptible(binder_user_error_wait,
|
|
|
|
binder_stop_on_user_error < 2);
|
|
|
|
}
|
2017-05-26 10:48:56 -07:00
|
|
|
binder_restore_priority(current, proc->default_priority);
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
2012-10-16 15:29:53 -07:00
|
|
|
|
2017-06-02 11:15:44 -07:00
|
|
|
if (non_block) {
|
|
|
|
if (!binder_has_work(thread, wait_for_proc_work))
|
|
|
|
ret = -EAGAIN;
|
2011-11-30 20:18:14 +09:00
|
|
|
} else {
|
2017-06-02 11:15:44 -07:00
|
|
|
ret = binder_wait_for_work(thread, wait_for_proc_work);
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
2012-10-16 15:29:53 -07:00
|
|
|
|
2011-11-30 20:18:14 +09:00
|
|
|
thread->looper &= ~BINDER_LOOPER_STATE_WAITING;
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
uint32_t cmd;
|
|
|
|
struct binder_transaction_data tr;
|
2016-10-20 10:33:00 -07:00
|
|
|
struct binder_work *w = NULL;
|
|
|
|
struct list_head *list = NULL;
|
2011-11-30 20:18:14 +09:00
|
|
|
struct binder_transaction *t = NULL;
|
2017-05-12 14:42:55 -07:00
|
|
|
struct binder_thread *t_from;
|
2011-11-30 20:18:14 +09:00
|
|
|
|
2017-03-21 13:06:01 -07:00
|
|
|
binder_inner_proc_lock(proc);
|
2016-10-20 10:33:00 -07:00
|
|
|
if (!binder_worklist_empty_ilocked(&thread->todo))
|
|
|
|
list = &thread->todo;
|
|
|
|
else if (!binder_worklist_empty_ilocked(&proc->todo) &&
|
|
|
|
wait_for_proc_work)
|
|
|
|
list = &proc->todo;
|
|
|
|
else {
|
|
|
|
binder_inner_proc_unlock(proc);
|
2011-11-30 20:18:14 +09:00
|
|
|
|
2014-09-08 18:16:34 +04:00
|
|
|
/* no data added */
|
2017-01-06 14:19:25 -08:00
|
|
|
if (ptr - buffer == 4 && !thread->looper_need_return)
|
2011-11-30 20:18:14 +09:00
|
|
|
goto retry;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-03-21 13:06:01 -07:00
|
|
|
if (end - ptr < sizeof(tr) + 4) {
|
|
|
|
binder_inner_proc_unlock(proc);
|
2011-11-30 20:18:14 +09:00
|
|
|
break;
|
2017-03-21 13:06:01 -07:00
|
|
|
}
|
2016-10-20 10:33:00 -07:00
|
|
|
w = binder_dequeue_work_head_ilocked(list);
|
2017-10-19 15:04:46 +02:00
|
|
|
if (binder_worklist_empty_ilocked(&thread->todo))
|
|
|
|
thread->process_todo = false;
|
2011-11-30 20:18:14 +09:00
|
|
|
|
|
|
|
switch (w->type) {
|
|
|
|
case BINDER_WORK_TRANSACTION: {
|
2017-03-21 13:06:01 -07:00
|
|
|
binder_inner_proc_unlock(proc);
|
2011-11-30 20:18:14 +09:00
|
|
|
t = container_of(w, struct binder_transaction, work);
|
|
|
|
} break;
|
2017-04-21 17:35:12 -07:00
|
|
|
case BINDER_WORK_RETURN_ERROR: {
|
|
|
|
struct binder_error *e = container_of(
|
|
|
|
w, struct binder_error, work);
|
|
|
|
|
|
|
|
WARN_ON(e->cmd == BR_OK);
|
2017-03-21 13:06:01 -07:00
|
|
|
binder_inner_proc_unlock(proc);
|
2017-04-21 17:35:12 -07:00
|
|
|
if (put_user(e->cmd, (uint32_t __user *)ptr))
|
|
|
|
return -EFAULT;
|
|
|
|
e->cmd = BR_OK;
|
|
|
|
ptr += sizeof(uint32_t);
|
|
|
|
|
|
|
|
binder_stat_br(proc, thread, cmd);
|
|
|
|
} break;
|
2011-11-30 20:18:14 +09:00
|
|
|
case BINDER_WORK_TRANSACTION_COMPLETE: {
|
2017-03-21 13:06:01 -07:00
|
|
|
binder_inner_proc_unlock(proc);
|
2011-11-30 20:18:14 +09:00
|
|
|
cmd = BR_TRANSACTION_COMPLETE;
|
2017-07-26 05:01:18 -07:00
|
|
|
if (put_user(cmd, (uint32_t __user *)ptr))
|
2011-11-30 20:18:14 +09:00
|
|
|
return -EFAULT;
|
|
|
|
ptr += sizeof(uint32_t);
|
|
|
|
|
|
|
|
binder_stat_br(proc, thread, cmd);
|
|
|
|
binder_debug(BINDER_DEBUG_TRANSACTION_COMPLETE,
|
2012-10-30 22:35:43 +05:30
|
|
|
"%d:%d BR_TRANSACTION_COMPLETE\n",
|
2011-11-30 20:18:14 +09:00
|
|
|
proc->pid, thread->pid);
|
|
|
|
kfree(w);
|
|
|
|
binder_stats_deleted(BINDER_STAT_TRANSACTION_COMPLETE);
|
|
|
|
} break;
|
|
|
|
case BINDER_WORK_NODE: {
|
|
|
|
struct binder_node *node = container_of(w, struct binder_node, work);
|
2017-05-24 10:51:01 -07:00
|
|
|
int strong, weak;
|
|
|
|
binder_uintptr_t node_ptr = node->ptr;
|
|
|
|
binder_uintptr_t node_cookie = node->cookie;
|
|
|
|
int node_debug_id = node->debug_id;
|
|
|
|
int has_weak_ref;
|
|
|
|
int has_strong_ref;
|
|
|
|
void __user *orig_ptr = ptr;
|
|
|
|
|
|
|
|
BUG_ON(proc != node->proc);
|
|
|
|
strong = node->internal_strong_refs ||
|
|
|
|
node->local_strong_refs;
|
|
|
|
weak = !hlist_empty(&node->refs) ||
|
2017-05-09 11:08:05 -07:00
|
|
|
node->local_weak_refs ||
|
|
|
|
node->tmp_refs || strong;
|
2017-05-24 10:51:01 -07:00
|
|
|
has_strong_ref = node->has_strong_ref;
|
|
|
|
has_weak_ref = node->has_weak_ref;
|
|
|
|
|
|
|
|
if (weak && !has_weak_ref) {
|
2011-11-30 20:18:14 +09:00
|
|
|
node->has_weak_ref = 1;
|
|
|
|
node->pending_weak_ref = 1;
|
|
|
|
node->local_weak_refs++;
|
2017-05-24 10:51:01 -07:00
|
|
|
}
|
|
|
|
if (strong && !has_strong_ref) {
|
2011-11-30 20:18:14 +09:00
|
|
|
node->has_strong_ref = 1;
|
|
|
|
node->pending_strong_ref = 1;
|
|
|
|
node->local_strong_refs++;
|
2017-05-24 10:51:01 -07:00
|
|
|
}
|
|
|
|
if (!strong && has_strong_ref)
|
2011-11-30 20:18:14 +09:00
|
|
|
node->has_strong_ref = 0;
|
2017-05-24 10:51:01 -07:00
|
|
|
if (!weak && has_weak_ref)
|
2011-11-30 20:18:14 +09:00
|
|
|
node->has_weak_ref = 0;
|
2017-05-24 10:51:01 -07:00
|
|
|
if (!weak && !strong) {
|
|
|
|
binder_debug(BINDER_DEBUG_INTERNAL_REFS,
|
|
|
|
"%d:%d node %d u%016llx c%016llx deleted\n",
|
|
|
|
proc->pid, thread->pid,
|
|
|
|
node_debug_id,
|
|
|
|
(u64)node_ptr,
|
|
|
|
(u64)node_cookie);
|
|
|
|
rb_erase(&node->rb_node, &proc->nodes);
|
2017-03-21 13:06:01 -07:00
|
|
|
binder_inner_proc_unlock(proc);
|
2017-06-08 13:45:59 -07:00
|
|
|
binder_node_lock(node);
|
|
|
|
/*
|
|
|
|
* Acquire the node lock before freeing the
|
|
|
|
* node to serialize with other threads that
|
|
|
|
* may have been holding the node lock while
|
|
|
|
* decrementing this node (avoids race where
|
|
|
|
* this thread frees while the other thread
|
|
|
|
* is unlocking the node after the final
|
|
|
|
* decrement)
|
|
|
|
*/
|
|
|
|
binder_node_unlock(node);
|
2017-03-21 13:06:01 -07:00
|
|
|
binder_free_node(node);
|
|
|
|
} else
|
|
|
|
binder_inner_proc_unlock(proc);
|
|
|
|
|
2017-05-24 10:51:01 -07:00
|
|
|
if (weak && !has_weak_ref)
|
|
|
|
ret = binder_put_node_cmd(
|
|
|
|
proc, thread, &ptr, node_ptr,
|
|
|
|
node_cookie, node_debug_id,
|
|
|
|
BR_INCREFS, "BR_INCREFS");
|
|
|
|
if (!ret && strong && !has_strong_ref)
|
|
|
|
ret = binder_put_node_cmd(
|
|
|
|
proc, thread, &ptr, node_ptr,
|
|
|
|
node_cookie, node_debug_id,
|
|
|
|
BR_ACQUIRE, "BR_ACQUIRE");
|
|
|
|
if (!ret && !strong && has_strong_ref)
|
|
|
|
ret = binder_put_node_cmd(
|
|
|
|
proc, thread, &ptr, node_ptr,
|
|
|
|
node_cookie, node_debug_id,
|
|
|
|
BR_RELEASE, "BR_RELEASE");
|
|
|
|
if (!ret && !weak && has_weak_ref)
|
|
|
|
ret = binder_put_node_cmd(
|
|
|
|
proc, thread, &ptr, node_ptr,
|
|
|
|
node_cookie, node_debug_id,
|
|
|
|
BR_DECREFS, "BR_DECREFS");
|
|
|
|
if (orig_ptr == ptr)
|
|
|
|
binder_debug(BINDER_DEBUG_INTERNAL_REFS,
|
|
|
|
"%d:%d node %d u%016llx c%016llx state unchanged\n",
|
|
|
|
proc->pid, thread->pid,
|
|
|
|
node_debug_id,
|
|
|
|
(u64)node_ptr,
|
|
|
|
(u64)node_cookie);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2011-11-30 20:18:14 +09:00
|
|
|
} break;
|
|
|
|
case BINDER_WORK_DEAD_BINDER:
|
|
|
|
case BINDER_WORK_DEAD_BINDER_AND_CLEAR:
|
|
|
|
case BINDER_WORK_CLEAR_DEATH_NOTIFICATION: {
|
|
|
|
struct binder_ref_death *death;
|
|
|
|
uint32_t cmd;
|
2017-05-22 11:26:23 -07:00
|
|
|
binder_uintptr_t cookie;
|
2011-11-30 20:18:14 +09:00
|
|
|
|
|
|
|
death = container_of(w, struct binder_ref_death, work);
|
|
|
|
if (w->type == BINDER_WORK_CLEAR_DEATH_NOTIFICATION)
|
|
|
|
cmd = BR_CLEAR_DEATH_NOTIFICATION_DONE;
|
|
|
|
else
|
|
|
|
cmd = BR_DEAD_BINDER;
|
2017-05-22 11:26:23 -07:00
|
|
|
cookie = death->cookie;
|
|
|
|
|
2011-11-30 20:18:14 +09:00
|
|
|
binder_debug(BINDER_DEBUG_DEATH_NOTIFICATION,
|
2014-02-21 14:40:26 -08:00
|
|
|
"%d:%d %s %016llx\n",
|
2011-11-30 20:18:14 +09:00
|
|
|
proc->pid, thread->pid,
|
|
|
|
cmd == BR_DEAD_BINDER ?
|
|
|
|
"BR_DEAD_BINDER" :
|
|
|
|
"BR_CLEAR_DEATH_NOTIFICATION_DONE",
|
2017-05-22 11:26:23 -07:00
|
|
|
(u64)cookie);
|
2011-11-30 20:18:14 +09:00
|
|
|
if (w->type == BINDER_WORK_CLEAR_DEATH_NOTIFICATION) {
|
2017-05-22 11:26:23 -07:00
|
|
|
binder_inner_proc_unlock(proc);
|
2011-11-30 20:18:14 +09:00
|
|
|
kfree(death);
|
|
|
|
binder_stats_deleted(BINDER_STAT_DEATH);
|
2017-03-21 13:06:01 -07:00
|
|
|
} else {
|
2016-10-20 10:33:00 -07:00
|
|
|
binder_enqueue_work_ilocked(
|
|
|
|
w, &proc->delivered_death);
|
2017-03-21 13:06:01 -07:00
|
|
|
binder_inner_proc_unlock(proc);
|
|
|
|
}
|
2017-05-22 11:26:23 -07:00
|
|
|
if (put_user(cmd, (uint32_t __user *)ptr))
|
|
|
|
return -EFAULT;
|
|
|
|
ptr += sizeof(uint32_t);
|
|
|
|
if (put_user(cookie,
|
|
|
|
(binder_uintptr_t __user *)ptr))
|
|
|
|
return -EFAULT;
|
|
|
|
ptr += sizeof(binder_uintptr_t);
|
|
|
|
binder_stat_br(proc, thread, cmd);
|
2011-11-30 20:18:14 +09:00
|
|
|
if (cmd == BR_DEAD_BINDER)
|
|
|
|
goto done; /* DEAD_BINDER notifications can cause transactions */
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!t)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
BUG_ON(t->buffer == NULL);
|
|
|
|
if (t->buffer->target_node) {
|
|
|
|
struct binder_node *target_node = t->buffer->target_node;
|
2017-06-07 10:02:12 -07:00
|
|
|
struct binder_priority node_prio;
|
2014-05-01 01:30:23 +09:00
|
|
|
|
2011-11-30 20:18:14 +09:00
|
|
|
tr.target.ptr = target_node->ptr;
|
|
|
|
tr.cookie = target_node->cookie;
|
2017-06-07 10:02:12 -07:00
|
|
|
node_prio.sched_policy = target_node->sched_policy;
|
|
|
|
node_prio.prio = target_node->min_priority;
|
2017-06-23 10:13:43 -07:00
|
|
|
binder_transaction_priority(current, t, node_prio,
|
|
|
|
target_node->inherit_rt);
|
2011-11-30 20:18:14 +09:00
|
|
|
cmd = BR_TRANSACTION;
|
|
|
|
} else {
|
2014-02-21 14:40:26 -08:00
|
|
|
tr.target.ptr = 0;
|
|
|
|
tr.cookie = 0;
|
2011-11-30 20:18:14 +09:00
|
|
|
cmd = BR_REPLY;
|
|
|
|
}
|
|
|
|
tr.code = t->code;
|
|
|
|
tr.flags = t->flags;
|
2012-05-25 18:34:53 -06:00
|
|
|
tr.sender_euid = from_kuid(current_user_ns(), t->sender_euid);
|
2011-11-30 20:18:14 +09:00
|
|
|
|
2017-05-12 14:42:55 -07:00
|
|
|
t_from = binder_get_txn_from(t);
|
|
|
|
if (t_from) {
|
|
|
|
struct task_struct *sender = t_from->proc->tsk;
|
2014-05-01 01:30:23 +09:00
|
|
|
|
2011-11-30 20:18:14 +09:00
|
|
|
tr.sender_pid = task_tgid_nr_ns(sender,
|
2010-03-02 14:51:53 -08:00
|
|
|
task_active_pid_ns(current));
|
2011-11-30 20:18:14 +09:00
|
|
|
} else {
|
|
|
|
tr.sender_pid = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
tr.data_size = t->buffer->data_size;
|
|
|
|
tr.offsets_size = t->buffer->offsets_size;
|
2016-10-10 10:40:53 -07:00
|
|
|
tr.data.ptr.buffer = (binder_uintptr_t)
|
|
|
|
((uintptr_t)t->buffer->data +
|
|
|
|
binder_alloc_get_user_buffer_offset(&proc->alloc));
|
2011-11-30 20:18:14 +09:00
|
|
|
tr.data.ptr.offsets = tr.data.ptr.buffer +
|
|
|
|
ALIGN(t->buffer->data_size,
|
|
|
|
sizeof(void *));
|
|
|
|
|
2017-05-12 14:42:55 -07:00
|
|
|
if (put_user(cmd, (uint32_t __user *)ptr)) {
|
|
|
|
if (t_from)
|
|
|
|
binder_thread_dec_tmpref(t_from);
|
2017-08-24 15:23:36 +02:00
|
|
|
|
|
|
|
binder_cleanup_transaction(t, "put_user failed",
|
|
|
|
BR_FAILED_REPLY);
|
|
|
|
|
2011-11-30 20:18:14 +09:00
|
|
|
return -EFAULT;
|
2017-05-12 14:42:55 -07:00
|
|
|
}
|
2011-11-30 20:18:14 +09:00
|
|
|
ptr += sizeof(uint32_t);
|
2017-05-12 14:42:55 -07:00
|
|
|
if (copy_to_user(ptr, &tr, sizeof(tr))) {
|
|
|
|
if (t_from)
|
|
|
|
binder_thread_dec_tmpref(t_from);
|
2017-08-24 15:23:36 +02:00
|
|
|
|
|
|
|
binder_cleanup_transaction(t, "copy_to_user failed",
|
|
|
|
BR_FAILED_REPLY);
|
|
|
|
|
2011-11-30 20:18:14 +09:00
|
|
|
return -EFAULT;
|
2017-05-12 14:42:55 -07:00
|
|
|
}
|
2011-11-30 20:18:14 +09:00
|
|
|
ptr += sizeof(tr);
|
|
|
|
|
2012-10-16 15:29:53 -07:00
|
|
|
trace_binder_transaction_received(t);
|
2011-11-30 20:18:14 +09:00
|
|
|
binder_stat_br(proc, thread, cmd);
|
|
|
|
binder_debug(BINDER_DEBUG_TRANSACTION,
|
2014-02-21 14:40:26 -08:00
|
|
|
"%d:%d %s %d %d:%d, cmd %d size %zd-%zd ptr %016llx-%016llx\n",
|
2011-11-30 20:18:14 +09:00
|
|
|
proc->pid, thread->pid,
|
|
|
|
(cmd == BR_TRANSACTION) ? "BR_TRANSACTION" :
|
|
|
|
"BR_REPLY",
|
2017-05-12 14:42:55 -07:00
|
|
|
t->debug_id, t_from ? t_from->proc->pid : 0,
|
|
|
|
t_from ? t_from->pid : 0, cmd,
|
2011-11-30 20:18:14 +09:00
|
|
|
t->buffer->data_size, t->buffer->offsets_size,
|
2014-02-21 14:40:26 -08:00
|
|
|
(u64)tr.data.ptr.buffer, (u64)tr.data.ptr.offsets);
|
2011-11-30 20:18:14 +09:00
|
|
|
|
2017-05-12 14:42:55 -07:00
|
|
|
if (t_from)
|
|
|
|
binder_thread_dec_tmpref(t_from);
|
2011-11-30 20:18:14 +09:00
|
|
|
t->buffer->allow_user_free = 1;
|
|
|
|
if (cmd == BR_TRANSACTION && !(t->flags & TF_ONE_WAY)) {
|
2017-06-02 13:36:52 -07:00
|
|
|
binder_inner_proc_lock(thread->proc);
|
2011-11-30 20:18:14 +09:00
|
|
|
t->to_parent = thread->transaction_stack;
|
|
|
|
t->to_thread = thread;
|
|
|
|
thread->transaction_stack = t;
|
2017-06-02 13:36:52 -07:00
|
|
|
binder_inner_proc_unlock(thread->proc);
|
2011-11-30 20:18:14 +09:00
|
|
|
} else {
|
2017-03-30 18:02:13 -07:00
|
|
|
binder_free_transaction(t);
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
|
|
|
|
*consumed = ptr - buffer;
|
2017-05-25 17:35:02 -07:00
|
|
|
binder_inner_proc_lock(proc);
|
2017-06-02 11:15:44 -07:00
|
|
|
if (proc->requested_threads == 0 &&
|
|
|
|
list_empty(&thread->proc->waiting_threads) &&
|
2011-11-30 20:18:14 +09:00
|
|
|
proc->requested_threads_started < proc->max_threads &&
|
|
|
|
(thread->looper & (BINDER_LOOPER_STATE_REGISTERED |
|
|
|
|
BINDER_LOOPER_STATE_ENTERED)) /* the user-space code fails to */
|
|
|
|
/*spawn a new thread if we leave this out */) {
|
|
|
|
proc->requested_threads++;
|
2017-05-25 17:35:02 -07:00
|
|
|
binder_inner_proc_unlock(proc);
|
2011-11-30 20:18:14 +09:00
|
|
|
binder_debug(BINDER_DEBUG_THREADS,
|
2012-10-30 22:35:43 +05:30
|
|
|
"%d:%d BR_SPAWN_LOOPER\n",
|
2011-11-30 20:18:14 +09:00
|
|
|
proc->pid, thread->pid);
|
2017-07-26 05:01:18 -07:00
|
|
|
if (put_user(BR_SPAWN_LOOPER, (uint32_t __user *)buffer))
|
2011-11-30 20:18:14 +09:00
|
|
|
return -EFAULT;
|
2012-10-16 15:29:52 -07:00
|
|
|
binder_stat_br(proc, thread, BR_SPAWN_LOOPER);
|
2017-05-25 17:35:02 -07:00
|
|
|
} else
|
|
|
|
binder_inner_proc_unlock(proc);
|
2011-11-30 20:18:14 +09:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-10-20 10:33:00 -07:00
|
|
|
static void binder_release_work(struct binder_proc *proc,
|
|
|
|
struct list_head *list)
|
2011-11-30 20:18:14 +09:00
|
|
|
{
|
|
|
|
struct binder_work *w;
|
2014-05-01 01:30:23 +09:00
|
|
|
|
2016-10-20 10:33:00 -07:00
|
|
|
while (1) {
|
|
|
|
w = binder_dequeue_work_head(proc, list);
|
|
|
|
if (!w)
|
|
|
|
return;
|
|
|
|
|
2011-11-30 20:18:14 +09:00
|
|
|
switch (w->type) {
|
|
|
|
case BINDER_WORK_TRANSACTION: {
|
|
|
|
struct binder_transaction *t;
|
|
|
|
|
|
|
|
t = container_of(w, struct binder_transaction, work);
|
2017-08-24 15:23:36 +02:00
|
|
|
|
|
|
|
binder_cleanup_transaction(t, "process died.",
|
|
|
|
BR_DEAD_REPLY);
|
2011-11-30 20:18:14 +09:00
|
|
|
} break;
|
2017-04-21 17:35:12 -07:00
|
|
|
case BINDER_WORK_RETURN_ERROR: {
|
|
|
|
struct binder_error *e = container_of(
|
|
|
|
w, struct binder_error, work);
|
|
|
|
|
|
|
|
binder_debug(BINDER_DEBUG_DEAD_TRANSACTION,
|
|
|
|
"undelivered TRANSACTION_ERROR: %u\n",
|
|
|
|
e->cmd);
|
|
|
|
} break;
|
2011-11-30 20:18:14 +09:00
|
|
|
case BINDER_WORK_TRANSACTION_COMPLETE: {
|
2012-10-16 15:29:54 -07:00
|
|
|
binder_debug(BINDER_DEBUG_DEAD_TRANSACTION,
|
2012-10-30 22:35:43 +05:30
|
|
|
"undelivered TRANSACTION_COMPLETE\n");
|
2011-11-30 20:18:14 +09:00
|
|
|
kfree(w);
|
|
|
|
binder_stats_deleted(BINDER_STAT_TRANSACTION_COMPLETE);
|
|
|
|
} break;
|
2012-10-16 15:29:54 -07:00
|
|
|
case BINDER_WORK_DEAD_BINDER_AND_CLEAR:
|
|
|
|
case BINDER_WORK_CLEAR_DEATH_NOTIFICATION: {
|
|
|
|
struct binder_ref_death *death;
|
|
|
|
|
|
|
|
death = container_of(w, struct binder_ref_death, work);
|
|
|
|
binder_debug(BINDER_DEBUG_DEAD_TRANSACTION,
|
2014-02-21 14:40:26 -08:00
|
|
|
"undelivered death notification, %016llx\n",
|
|
|
|
(u64)death->cookie);
|
2012-10-16 15:29:54 -07:00
|
|
|
kfree(death);
|
|
|
|
binder_stats_deleted(BINDER_STAT_DEATH);
|
|
|
|
} break;
|
2011-11-30 20:18:14 +09:00
|
|
|
default:
|
2012-10-30 22:35:43 +05:30
|
|
|
pr_err("unexpected work type, %d, not freed\n",
|
2012-10-16 15:29:54 -07:00
|
|
|
w->type);
|
2011-11-30 20:18:14 +09:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-05-25 15:52:17 -07:00
|
|
|
static struct binder_thread *binder_get_thread_ilocked(
|
|
|
|
struct binder_proc *proc, struct binder_thread *new_thread)
|
2011-11-30 20:18:14 +09:00
|
|
|
{
|
|
|
|
struct binder_thread *thread = NULL;
|
|
|
|
struct rb_node *parent = NULL;
|
|
|
|
struct rb_node **p = &proc->threads.rb_node;
|
|
|
|
|
|
|
|
while (*p) {
|
|
|
|
parent = *p;
|
|
|
|
thread = rb_entry(parent, struct binder_thread, rb_node);
|
|
|
|
|
|
|
|
if (current->pid < thread->pid)
|
|
|
|
p = &(*p)->rb_left;
|
|
|
|
else if (current->pid > thread->pid)
|
|
|
|
p = &(*p)->rb_right;
|
|
|
|
else
|
2017-05-25 15:52:17 -07:00
|
|
|
return thread;
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
2017-05-25 15:52:17 -07:00
|
|
|
if (!new_thread)
|
|
|
|
return NULL;
|
|
|
|
thread = new_thread;
|
|
|
|
binder_stats_created(BINDER_STAT_THREAD);
|
|
|
|
thread->proc = proc;
|
|
|
|
thread->pid = current->pid;
|
2017-06-07 10:02:12 -07:00
|
|
|
get_task_struct(current);
|
|
|
|
thread->task = current;
|
2017-05-25 15:52:17 -07:00
|
|
|
atomic_set(&thread->tmp_ref, 0);
|
|
|
|
init_waitqueue_head(&thread->wait);
|
|
|
|
INIT_LIST_HEAD(&thread->todo);
|
|
|
|
rb_link_node(&thread->rb_node, parent, p);
|
|
|
|
rb_insert_color(&thread->rb_node, &proc->threads);
|
|
|
|
thread->looper_need_return = true;
|
|
|
|
thread->return_error.work.type = BINDER_WORK_RETURN_ERROR;
|
|
|
|
thread->return_error.cmd = BR_OK;
|
|
|
|
thread->reply_error.work.type = BINDER_WORK_RETURN_ERROR;
|
|
|
|
thread->reply_error.cmd = BR_OK;
|
2017-06-02 11:15:44 -07:00
|
|
|
INIT_LIST_HEAD(&new_thread->waiting_thread_node);
|
2017-05-25 15:52:17 -07:00
|
|
|
return thread;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct binder_thread *binder_get_thread(struct binder_proc *proc)
|
|
|
|
{
|
|
|
|
struct binder_thread *thread;
|
|
|
|
struct binder_thread *new_thread;
|
|
|
|
|
|
|
|
binder_inner_proc_lock(proc);
|
|
|
|
thread = binder_get_thread_ilocked(proc, NULL);
|
|
|
|
binder_inner_proc_unlock(proc);
|
|
|
|
if (!thread) {
|
|
|
|
new_thread = kzalloc(sizeof(*thread), GFP_KERNEL);
|
|
|
|
if (new_thread == NULL)
|
2011-11-30 20:18:14 +09:00
|
|
|
return NULL;
|
2017-05-25 15:52:17 -07:00
|
|
|
binder_inner_proc_lock(proc);
|
|
|
|
thread = binder_get_thread_ilocked(proc, new_thread);
|
|
|
|
binder_inner_proc_unlock(proc);
|
|
|
|
if (thread != new_thread)
|
|
|
|
kfree(new_thread);
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
|
|
|
return thread;
|
|
|
|
}
|
|
|
|
|
2017-05-12 14:42:55 -07:00
|
|
|
static void binder_free_proc(struct binder_proc *proc)
|
|
|
|
{
|
|
|
|
BUG_ON(!list_empty(&proc->todo));
|
|
|
|
BUG_ON(!list_empty(&proc->delivered_death));
|
|
|
|
binder_alloc_deferred_release(&proc->alloc);
|
|
|
|
put_task_struct(proc->tsk);
|
|
|
|
binder_stats_deleted(BINDER_STAT_PROC);
|
|
|
|
kfree(proc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void binder_free_thread(struct binder_thread *thread)
|
|
|
|
{
|
|
|
|
BUG_ON(!list_empty(&thread->todo));
|
|
|
|
binder_stats_deleted(BINDER_STAT_THREAD);
|
|
|
|
binder_proc_dec_tmpref(thread->proc);
|
2017-06-07 10:02:12 -07:00
|
|
|
put_task_struct(thread->task);
|
2017-05-12 14:42:55 -07:00
|
|
|
kfree(thread);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int binder_thread_release(struct binder_proc *proc,
|
|
|
|
struct binder_thread *thread)
|
2011-11-30 20:18:14 +09:00
|
|
|
{
|
|
|
|
struct binder_transaction *t;
|
|
|
|
struct binder_transaction *send_reply = NULL;
|
|
|
|
int active_transactions = 0;
|
2017-05-12 14:42:55 -07:00
|
|
|
struct binder_transaction *last_t = NULL;
|
2011-11-30 20:18:14 +09:00
|
|
|
|
2017-05-25 15:52:17 -07:00
|
|
|
binder_inner_proc_lock(thread->proc);
|
2017-05-12 14:42:55 -07:00
|
|
|
/*
|
|
|
|
* take a ref on the proc so it survives
|
|
|
|
* after we remove this thread from proc->threads.
|
|
|
|
* The corresponding dec is when we actually
|
|
|
|
* free the thread in binder_free_thread()
|
|
|
|
*/
|
|
|
|
proc->tmp_ref++;
|
|
|
|
/*
|
|
|
|
* take a ref on this thread to ensure it
|
|
|
|
* survives while we are releasing it
|
|
|
|
*/
|
|
|
|
atomic_inc(&thread->tmp_ref);
|
2011-11-30 20:18:14 +09:00
|
|
|
rb_erase(&thread->rb_node, &proc->threads);
|
|
|
|
t = thread->transaction_stack;
|
2017-05-12 14:42:55 -07:00
|
|
|
if (t) {
|
|
|
|
spin_lock(&t->lock);
|
|
|
|
if (t->to_thread == thread)
|
|
|
|
send_reply = t;
|
|
|
|
}
|
|
|
|
thread->is_dead = true;
|
|
|
|
|
2011-11-30 20:18:14 +09:00
|
|
|
while (t) {
|
2017-05-12 14:42:55 -07:00
|
|
|
last_t = t;
|
2011-11-30 20:18:14 +09:00
|
|
|
active_transactions++;
|
|
|
|
binder_debug(BINDER_DEBUG_DEAD_TRANSACTION,
|
2012-10-30 22:35:43 +05:30
|
|
|
"release %d:%d transaction %d %s, still active\n",
|
|
|
|
proc->pid, thread->pid,
|
2011-11-30 20:18:14 +09:00
|
|
|
t->debug_id,
|
|
|
|
(t->to_thread == thread) ? "in" : "out");
|
|
|
|
|
|
|
|
if (t->to_thread == thread) {
|
|
|
|
t->to_proc = NULL;
|
|
|
|
t->to_thread = NULL;
|
|
|
|
if (t->buffer) {
|
|
|
|
t->buffer->transaction = NULL;
|
|
|
|
t->buffer = NULL;
|
|
|
|
}
|
|
|
|
t = t->to_parent;
|
|
|
|
} else if (t->from == thread) {
|
|
|
|
t->from = NULL;
|
|
|
|
t = t->from_parent;
|
|
|
|
} else
|
|
|
|
BUG();
|
2017-05-12 14:42:55 -07:00
|
|
|
spin_unlock(&last_t->lock);
|
|
|
|
if (t)
|
|
|
|
spin_lock(&t->lock);
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
2018-01-05 11:27:07 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If this thread used poll, make sure we remove the waitqueue
|
|
|
|
* from any epoll data structures holding it with POLLFREE.
|
|
|
|
* waitqueue_active() is safe to use here because we're holding
|
|
|
|
* the inner lock.
|
|
|
|
*/
|
|
|
|
if ((thread->looper & BINDER_LOOPER_STATE_POLL) &&
|
|
|
|
waitqueue_active(&thread->wait)) {
|
|
|
|
wake_up_poll(&thread->wait, POLLHUP | POLLFREE);
|
|
|
|
}
|
|
|
|
|
2017-05-25 15:52:17 -07:00
|
|
|
binder_inner_proc_unlock(thread->proc);
|
2017-05-12 14:42:55 -07:00
|
|
|
|
2018-02-16 09:47:15 +01:00
|
|
|
/*
|
|
|
|
* This is needed to avoid races between wake_up_poll() above and
|
|
|
|
* and ep_remove_waitqueue() called for other reasons (eg the epoll file
|
|
|
|
* descriptor being closed); ep_remove_waitqueue() holds an RCU read
|
|
|
|
* lock, so we can be sure it's done after calling synchronize_rcu().
|
|
|
|
*/
|
|
|
|
if (thread->looper & BINDER_LOOPER_STATE_POLL)
|
|
|
|
synchronize_rcu();
|
|
|
|
|
2011-11-30 20:18:14 +09:00
|
|
|
if (send_reply)
|
|
|
|
binder_send_failed_reply(send_reply, BR_DEAD_REPLY);
|
2016-10-20 10:33:00 -07:00
|
|
|
binder_release_work(proc, &thread->todo);
|
2017-05-12 14:42:55 -07:00
|
|
|
binder_thread_dec_tmpref(thread);
|
2011-11-30 20:18:14 +09:00
|
|
|
return active_transactions;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int binder_poll(struct file *filp,
|
|
|
|
struct poll_table_struct *wait)
|
|
|
|
{
|
|
|
|
struct binder_proc *proc = filp->private_data;
|
|
|
|
struct binder_thread *thread = NULL;
|
2017-06-02 11:15:44 -07:00
|
|
|
bool wait_for_proc_work;
|
2012-10-16 15:29:53 -07:00
|
|
|
|
2011-11-30 20:18:14 +09:00
|
|
|
thread = binder_get_thread(proc);
|
2018-01-30 23:11:24 -08:00
|
|
|
if (!thread)
|
|
|
|
return POLLERR;
|
2011-11-30 20:18:14 +09:00
|
|
|
|
2017-06-02 13:36:52 -07:00
|
|
|
binder_inner_proc_lock(thread->proc);
|
2017-06-02 11:15:44 -07:00
|
|
|
thread->looper |= BINDER_LOOPER_STATE_POLL;
|
|
|
|
wait_for_proc_work = binder_available_for_proc_work_ilocked(thread);
|
2012-10-16 15:29:53 -07:00
|
|
|
|
2017-06-02 13:36:52 -07:00
|
|
|
binder_inner_proc_unlock(thread->proc);
|
2012-10-16 15:29:53 -07:00
|
|
|
|
2017-06-02 11:15:44 -07:00
|
|
|
poll_wait(filp, &thread->wait, wait);
|
|
|
|
|
2017-08-10 12:32:00 +02:00
|
|
|
if (binder_has_work(thread, wait_for_proc_work))
|
2017-06-02 11:15:44 -07:00
|
|
|
return POLLIN;
|
2011-11-30 20:18:14 +09:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-06-03 22:27:21 +03:00
|
|
|
static int binder_ioctl_write_read(struct file *filp,
|
|
|
|
unsigned int cmd, unsigned long arg,
|
|
|
|
struct binder_thread *thread)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
struct binder_proc *proc = filp->private_data;
|
|
|
|
unsigned int size = _IOC_SIZE(cmd);
|
|
|
|
void __user *ubuf = (void __user *)arg;
|
|
|
|
struct binder_write_read bwr;
|
|
|
|
|
|
|
|
if (size != sizeof(struct binder_write_read)) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
2017-07-26 05:01:18 -07:00
|
|
|
if (copy_from_user(&bwr, ubuf, sizeof(bwr))) {
|
2014-06-03 22:27:21 +03:00
|
|
|
ret = -EFAULT;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
binder_debug(BINDER_DEBUG_READ_WRITE,
|
|
|
|
"%d:%d write %lld at %016llx, read %lld at %016llx\n",
|
|
|
|
proc->pid, thread->pid,
|
|
|
|
(u64)bwr.write_size, (u64)bwr.write_buffer,
|
|
|
|
(u64)bwr.read_size, (u64)bwr.read_buffer);
|
|
|
|
|
|
|
|
if (bwr.write_size > 0) {
|
|
|
|
ret = binder_thread_write(proc, thread,
|
|
|
|
bwr.write_buffer,
|
|
|
|
bwr.write_size,
|
|
|
|
&bwr.write_consumed);
|
|
|
|
trace_binder_write_done(ret);
|
|
|
|
if (ret < 0) {
|
|
|
|
bwr.read_consumed = 0;
|
2017-07-26 05:01:18 -07:00
|
|
|
if (copy_to_user(ubuf, &bwr, sizeof(bwr)))
|
2014-06-03 22:27:21 +03:00
|
|
|
ret = -EFAULT;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (bwr.read_size > 0) {
|
|
|
|
ret = binder_thread_read(proc, thread, bwr.read_buffer,
|
|
|
|
bwr.read_size,
|
|
|
|
&bwr.read_consumed,
|
|
|
|
filp->f_flags & O_NONBLOCK);
|
|
|
|
trace_binder_read_done(ret);
|
2017-06-02 11:15:44 -07:00
|
|
|
binder_inner_proc_lock(proc);
|
|
|
|
if (!binder_worklist_empty_ilocked(&proc->todo))
|
2017-06-06 15:17:46 -07:00
|
|
|
binder_wakeup_proc_ilocked(proc);
|
2017-06-02 11:15:44 -07:00
|
|
|
binder_inner_proc_unlock(proc);
|
2014-06-03 22:27:21 +03:00
|
|
|
if (ret < 0) {
|
2017-07-26 05:01:18 -07:00
|
|
|
if (copy_to_user(ubuf, &bwr, sizeof(bwr)))
|
2014-06-03 22:27:21 +03:00
|
|
|
ret = -EFAULT;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
binder_debug(BINDER_DEBUG_READ_WRITE,
|
|
|
|
"%d:%d wrote %lld of %lld, read return %lld of %lld\n",
|
|
|
|
proc->pid, thread->pid,
|
|
|
|
(u64)bwr.write_consumed, (u64)bwr.write_size,
|
|
|
|
(u64)bwr.read_consumed, (u64)bwr.read_size);
|
2017-07-26 05:01:18 -07:00
|
|
|
if (copy_to_user(ubuf, &bwr, sizeof(bwr))) {
|
2014-06-03 22:27:21 +03:00
|
|
|
ret = -EFAULT;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int binder_ioctl_set_ctx_mgr(struct file *filp)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
struct binder_proc *proc = filp->private_data;
|
2016-09-30 15:51:48 +02:00
|
|
|
struct binder_context *context = proc->context;
|
2016-10-17 12:33:15 -07:00
|
|
|
struct binder_node *new_node;
|
2014-06-03 22:27:21 +03:00
|
|
|
kuid_t curr_euid = current_euid();
|
|
|
|
|
2016-10-17 12:33:15 -07:00
|
|
|
mutex_lock(&context->context_mgr_node_lock);
|
2016-09-30 15:51:48 +02:00
|
|
|
if (context->binder_context_mgr_node) {
|
2014-06-03 22:27:21 +03:00
|
|
|
pr_err("BINDER_SET_CONTEXT_MGR already set\n");
|
|
|
|
ret = -EBUSY;
|
|
|
|
goto out;
|
|
|
|
}
|
2015-01-21 10:54:10 -05:00
|
|
|
ret = security_binder_set_context_mgr(proc->tsk);
|
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
2016-09-30 15:51:48 +02:00
|
|
|
if (uid_valid(context->binder_context_mgr_uid)) {
|
|
|
|
if (!uid_eq(context->binder_context_mgr_uid, curr_euid)) {
|
2014-06-03 22:27:21 +03:00
|
|
|
pr_err("BINDER_SET_CONTEXT_MGR bad uid %d != %d\n",
|
|
|
|
from_kuid(&init_user_ns, curr_euid),
|
|
|
|
from_kuid(&init_user_ns,
|
2016-09-30 15:51:48 +02:00
|
|
|
context->binder_context_mgr_uid));
|
2014-06-03 22:27:21 +03:00
|
|
|
ret = -EPERM;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
} else {
|
2016-09-30 15:51:48 +02:00
|
|
|
context->binder_context_mgr_uid = curr_euid;
|
2014-06-03 22:27:21 +03:00
|
|
|
}
|
2017-06-08 13:45:59 -07:00
|
|
|
new_node = binder_new_node(proc, NULL);
|
2016-10-17 12:33:15 -07:00
|
|
|
if (!new_node) {
|
2014-06-03 22:27:21 +03:00
|
|
|
ret = -ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
2017-06-08 13:45:59 -07:00
|
|
|
binder_node_lock(new_node);
|
2016-10-17 12:33:15 -07:00
|
|
|
new_node->local_weak_refs++;
|
|
|
|
new_node->local_strong_refs++;
|
|
|
|
new_node->has_strong_ref = 1;
|
|
|
|
new_node->has_weak_ref = 1;
|
|
|
|
context->binder_context_mgr_node = new_node;
|
2017-06-08 13:45:59 -07:00
|
|
|
binder_node_unlock(new_node);
|
2017-05-09 11:08:05 -07:00
|
|
|
binder_put_node(new_node);
|
2014-06-03 22:27:21 +03:00
|
|
|
out:
|
2016-10-17 12:33:15 -07:00
|
|
|
mutex_unlock(&context->context_mgr_node_lock);
|
2014-06-03 22:27:21 +03:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-06-20 13:54:44 -07:00
|
|
|
static int binder_ioctl_get_node_debug_info(struct binder_proc *proc,
|
|
|
|
struct binder_node_debug_info *info) {
|
|
|
|
struct rb_node *n;
|
|
|
|
binder_uintptr_t ptr = info->ptr;
|
|
|
|
|
|
|
|
memset(info, 0, sizeof(*info));
|
|
|
|
|
|
|
|
binder_inner_proc_lock(proc);
|
|
|
|
for (n = rb_first(&proc->nodes); n != NULL; n = rb_next(n)) {
|
|
|
|
struct binder_node *node = rb_entry(n, struct binder_node,
|
|
|
|
rb_node);
|
|
|
|
if (node->ptr > ptr) {
|
|
|
|
info->ptr = node->ptr;
|
|
|
|
info->cookie = node->cookie;
|
|
|
|
info->has_strong_ref = node->has_strong_ref;
|
|
|
|
info->has_weak_ref = node->has_weak_ref;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
binder_inner_proc_unlock(proc);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-11-30 20:18:14 +09:00
|
|
|
static long binder_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct binder_proc *proc = filp->private_data;
|
|
|
|
struct binder_thread *thread;
|
|
|
|
unsigned int size = _IOC_SIZE(cmd);
|
|
|
|
void __user *ubuf = (void __user *)arg;
|
|
|
|
|
2014-06-03 22:27:21 +03:00
|
|
|
/*pr_info("binder_ioctl: %d:%d %x %lx\n",
|
|
|
|
proc->pid, current->pid, cmd, arg);*/
|
2011-11-30 20:18:14 +09:00
|
|
|
|
2017-06-22 14:37:45 -07:00
|
|
|
binder_selftest_alloc(&proc->alloc);
|
|
|
|
|
2012-10-16 15:29:53 -07:00
|
|
|
trace_binder_ioctl(cmd, arg);
|
|
|
|
|
2011-11-30 20:18:14 +09:00
|
|
|
ret = wait_event_interruptible(binder_user_error_wait, binder_stop_on_user_error < 2);
|
|
|
|
if (ret)
|
2012-10-16 15:29:53 -07:00
|
|
|
goto err_unlocked;
|
2011-11-30 20:18:14 +09:00
|
|
|
|
|
|
|
thread = binder_get_thread(proc);
|
|
|
|
if (thread == NULL) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (cmd) {
|
2014-06-03 22:27:21 +03:00
|
|
|
case BINDER_WRITE_READ:
|
|
|
|
ret = binder_ioctl_write_read(filp, cmd, arg, thread);
|
|
|
|
if (ret)
|
2011-11-30 20:18:14 +09:00
|
|
|
goto err;
|
|
|
|
break;
|
2017-05-25 17:35:02 -07:00
|
|
|
case BINDER_SET_MAX_THREADS: {
|
|
|
|
int max_threads;
|
|
|
|
|
|
|
|
if (copy_from_user(&max_threads, ubuf,
|
|
|
|
sizeof(max_threads))) {
|
2011-11-30 20:18:14 +09:00
|
|
|
ret = -EINVAL;
|
|
|
|
goto err;
|
|
|
|
}
|
2017-05-25 17:35:02 -07:00
|
|
|
binder_inner_proc_lock(proc);
|
|
|
|
proc->max_threads = max_threads;
|
|
|
|
binder_inner_proc_unlock(proc);
|
2011-11-30 20:18:14 +09:00
|
|
|
break;
|
2017-05-25 17:35:02 -07:00
|
|
|
}
|
2011-11-30 20:18:14 +09:00
|
|
|
case BINDER_SET_CONTEXT_MGR:
|
2014-06-03 22:27:21 +03:00
|
|
|
ret = binder_ioctl_set_ctx_mgr(filp);
|
|
|
|
if (ret)
|
2011-11-30 20:18:14 +09:00
|
|
|
goto err;
|
|
|
|
break;
|
|
|
|
case BINDER_THREAD_EXIT:
|
2012-10-30 22:35:43 +05:30
|
|
|
binder_debug(BINDER_DEBUG_THREADS, "%d:%d exit\n",
|
2011-11-30 20:18:14 +09:00
|
|
|
proc->pid, thread->pid);
|
2017-05-12 14:42:55 -07:00
|
|
|
binder_thread_release(proc, thread);
|
2011-11-30 20:18:14 +09:00
|
|
|
thread = NULL;
|
|
|
|
break;
|
2014-04-15 12:03:05 +02:00
|
|
|
case BINDER_VERSION: {
|
|
|
|
struct binder_version __user *ver = ubuf;
|
|
|
|
|
2011-11-30 20:18:14 +09:00
|
|
|
if (size != sizeof(struct binder_version)) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto err;
|
|
|
|
}
|
2017-07-26 05:01:18 -07:00
|
|
|
if (put_user(BINDER_CURRENT_PROTOCOL_VERSION,
|
|
|
|
&ver->protocol_version)) {
|
|
|
|
ret = -EINVAL;
|
2011-11-30 20:18:14 +09:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
break;
|
2014-04-15 12:03:05 +02:00
|
|
|
}
|
2017-06-20 13:54:44 -07:00
|
|
|
case BINDER_GET_NODE_DEBUG_INFO: {
|
|
|
|
struct binder_node_debug_info info;
|
|
|
|
|
|
|
|
if (copy_from_user(&info, ubuf, sizeof(info))) {
|
|
|
|
ret = -EFAULT;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = binder_ioctl_get_node_debug_info(proc, &info);
|
|
|
|
if (ret < 0)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
if (copy_to_user(ubuf, &info, sizeof(info))) {
|
|
|
|
ret = -EFAULT;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2011-11-30 20:18:14 +09:00
|
|
|
default:
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
ret = 0;
|
|
|
|
err:
|
|
|
|
if (thread)
|
2017-01-06 14:19:25 -08:00
|
|
|
thread->looper_need_return = false;
|
2011-11-30 20:18:14 +09:00
|
|
|
wait_event_interruptible(binder_user_error_wait, binder_stop_on_user_error < 2);
|
|
|
|
if (ret && ret != -ERESTARTSYS)
|
2012-10-30 22:35:43 +05:30
|
|
|
pr_info("%d:%d ioctl %x %lx returned %d\n", proc->pid, current->pid, cmd, arg, ret);
|
2012-10-16 15:29:53 -07:00
|
|
|
err_unlocked:
|
|
|
|
trace_binder_ioctl_done(ret);
|
2011-11-30 20:18:14 +09:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void binder_vma_open(struct vm_area_struct *vma)
|
|
|
|
{
|
|
|
|
struct binder_proc *proc = vma->vm_private_data;
|
2014-05-01 01:30:23 +09:00
|
|
|
|
2011-11-30 20:18:14 +09:00
|
|
|
binder_debug(BINDER_DEBUG_OPEN_CLOSE,
|
2012-10-30 22:35:43 +05:30
|
|
|
"%d open vm area %lx-%lx (%ld K) vma %lx pagep %lx\n",
|
2011-11-30 20:18:14 +09:00
|
|
|
proc->pid, vma->vm_start, vma->vm_end,
|
|
|
|
(vma->vm_end - vma->vm_start) / SZ_1K, vma->vm_flags,
|
|
|
|
(unsigned long)pgprot_val(vma->vm_page_prot));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void binder_vma_close(struct vm_area_struct *vma)
|
|
|
|
{
|
|
|
|
struct binder_proc *proc = vma->vm_private_data;
|
2014-05-01 01:30:23 +09:00
|
|
|
|
2011-11-30 20:18:14 +09:00
|
|
|
binder_debug(BINDER_DEBUG_OPEN_CLOSE,
|
2012-10-30 22:35:43 +05:30
|
|
|
"%d close vm area %lx-%lx (%ld K) vma %lx pagep %lx\n",
|
2011-11-30 20:18:14 +09:00
|
|
|
proc->pid, vma->vm_start, vma->vm_end,
|
|
|
|
(vma->vm_end - vma->vm_start) / SZ_1K, vma->vm_flags,
|
|
|
|
(unsigned long)pgprot_val(vma->vm_page_prot));
|
2016-10-10 10:40:53 -07:00
|
|
|
binder_alloc_vma_close(&proc->alloc);
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
|
|
|
|
2014-06-02 18:17:59 +05:30
|
|
|
static int binder_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
|
|
|
|
{
|
|
|
|
return VM_FAULT_SIGBUS;
|
|
|
|
}
|
|
|
|
|
2015-09-09 15:39:26 -07:00
|
|
|
static const struct vm_operations_struct binder_vm_ops = {
|
2011-11-30 20:18:14 +09:00
|
|
|
.open = binder_vma_open,
|
|
|
|
.close = binder_vma_close,
|
2014-06-02 18:17:59 +05:30
|
|
|
.fault = binder_vm_fault,
|
2011-11-30 20:18:14 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
static int binder_mmap(struct file *filp, struct vm_area_struct *vma)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct binder_proc *proc = filp->private_data;
|
|
|
|
const char *failure_string;
|
|
|
|
|
2017-03-07 15:51:18 +01:00
|
|
|
if (proc->tsk != current->group_leader)
|
2012-08-15 18:23:36 -04:00
|
|
|
return -EINVAL;
|
|
|
|
|
2011-11-30 20:18:14 +09:00
|
|
|
if ((vma->vm_end - vma->vm_start) > SZ_4M)
|
|
|
|
vma->vm_end = vma->vm_start + SZ_4M;
|
|
|
|
|
|
|
|
binder_debug(BINDER_DEBUG_OPEN_CLOSE,
|
2016-10-10 10:40:53 -07:00
|
|
|
"%s: %d %lx-%lx (%ld K) vma %lx pagep %lx\n",
|
|
|
|
__func__, proc->pid, vma->vm_start, vma->vm_end,
|
2011-11-30 20:18:14 +09:00
|
|
|
(vma->vm_end - vma->vm_start) / SZ_1K, vma->vm_flags,
|
|
|
|
(unsigned long)pgprot_val(vma->vm_page_prot));
|
|
|
|
|
|
|
|
if (vma->vm_flags & FORBIDDEN_MMAP_FLAGS) {
|
|
|
|
ret = -EPERM;
|
|
|
|
failure_string = "bad vm_flags";
|
|
|
|
goto err_bad_arg;
|
|
|
|
}
|
|
|
|
vma->vm_flags = (vma->vm_flags | VM_DONTCOPY) & ~VM_MAYWRITE;
|
|
|
|
vma->vm_ops = &binder_vm_ops;
|
|
|
|
vma->vm_private_data = proc;
|
|
|
|
|
2016-10-10 10:40:53 -07:00
|
|
|
ret = binder_alloc_mmap_handler(&proc->alloc, vma);
|
2017-11-10 15:30:27 -08:00
|
|
|
|
|
|
|
return ret;
|
2011-11-30 20:18:14 +09:00
|
|
|
|
|
|
|
err_bad_arg:
|
2012-06-26 02:00:30 -04:00
|
|
|
pr_err("binder_mmap: %d %lx-%lx %s failed %d\n",
|
2011-11-30 20:18:14 +09:00
|
|
|
proc->pid, vma->vm_start, vma->vm_end, failure_string, ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int binder_open(struct inode *nodp, struct file *filp)
|
|
|
|
{
|
|
|
|
struct binder_proc *proc;
|
2016-09-30 16:08:09 +02:00
|
|
|
struct binder_device *binder_dev;
|
2011-11-30 20:18:14 +09:00
|
|
|
|
|
|
|
binder_debug(BINDER_DEBUG_OPEN_CLOSE, "binder_open: %d:%d\n",
|
|
|
|
current->group_leader->pid, current->pid);
|
|
|
|
|
|
|
|
proc = kzalloc(sizeof(*proc), GFP_KERNEL);
|
|
|
|
if (proc == NULL)
|
|
|
|
return -ENOMEM;
|
2017-05-29 16:44:24 -07:00
|
|
|
spin_lock_init(&proc->inner_lock);
|
|
|
|
spin_lock_init(&proc->outer_lock);
|
2017-03-07 15:51:18 +01:00
|
|
|
get_task_struct(current->group_leader);
|
|
|
|
proc->tsk = current->group_leader;
|
2011-11-30 20:18:14 +09:00
|
|
|
INIT_LIST_HEAD(&proc->todo);
|
2017-06-06 17:04:42 -07:00
|
|
|
if (binder_supported_policy(current->policy)) {
|
|
|
|
proc->default_priority.sched_policy = current->policy;
|
|
|
|
proc->default_priority.prio = current->normal_prio;
|
|
|
|
} else {
|
|
|
|
proc->default_priority.sched_policy = SCHED_NORMAL;
|
|
|
|
proc->default_priority.prio = NICE_TO_PRIO(0);
|
|
|
|
}
|
|
|
|
|
2016-09-30 16:08:09 +02:00
|
|
|
binder_dev = container_of(filp->private_data, struct binder_device,
|
|
|
|
miscdev);
|
|
|
|
proc->context = &binder_dev->context;
|
2016-10-10 10:40:53 -07:00
|
|
|
binder_alloc_init(&proc->alloc);
|
2012-10-16 15:29:53 -07:00
|
|
|
|
2011-11-30 20:18:14 +09:00
|
|
|
binder_stats_created(BINDER_STAT_PROC);
|
|
|
|
proc->pid = current->group_leader->pid;
|
|
|
|
INIT_LIST_HEAD(&proc->delivered_death);
|
2017-06-02 11:15:44 -07:00
|
|
|
INIT_LIST_HEAD(&proc->waiting_threads);
|
2011-11-30 20:18:14 +09:00
|
|
|
filp->private_data = proc;
|
2012-10-16 15:29:53 -07:00
|
|
|
|
2016-10-17 12:33:15 -07:00
|
|
|
mutex_lock(&binder_procs_lock);
|
|
|
|
hlist_add_head(&proc->proc_node, &binder_procs);
|
|
|
|
mutex_unlock(&binder_procs_lock);
|
2011-11-30 20:18:14 +09:00
|
|
|
|
2009-04-28 20:57:50 -07:00
|
|
|
if (binder_debugfs_dir_entry_proc) {
|
2011-11-30 20:18:14 +09:00
|
|
|
char strbuf[11];
|
2014-05-01 01:30:23 +09:00
|
|
|
|
2011-11-30 20:18:14 +09:00
|
|
|
snprintf(strbuf, sizeof(strbuf), "%u", proc->pid);
|
2016-10-17 15:17:31 +02:00
|
|
|
/*
|
|
|
|
* proc debug entries are shared between contexts, so
|
|
|
|
* this will fail if the process tries to open the driver
|
|
|
|
* again with a different context. The priting code will
|
|
|
|
* anyway print all contexts that a given PID has, so this
|
|
|
|
* is not a problem.
|
|
|
|
*/
|
2009-04-28 20:57:50 -07:00
|
|
|
proc->debugfs_entry = debugfs_create_file(strbuf, S_IRUGO,
|
2016-10-17 15:17:31 +02:00
|
|
|
binder_debugfs_dir_entry_proc,
|
|
|
|
(void *)(unsigned long)proc->pid,
|
|
|
|
&binder_proc_fops);
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int binder_flush(struct file *filp, fl_owner_t id)
|
|
|
|
{
|
|
|
|
struct binder_proc *proc = filp->private_data;
|
|
|
|
|
|
|
|
binder_defer_work(proc, BINDER_DEFERRED_FLUSH);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void binder_deferred_flush(struct binder_proc *proc)
|
|
|
|
{
|
|
|
|
struct rb_node *n;
|
|
|
|
int wake_count = 0;
|
2014-05-01 01:30:23 +09:00
|
|
|
|
2017-05-25 15:52:17 -07:00
|
|
|
binder_inner_proc_lock(proc);
|
2011-11-30 20:18:14 +09:00
|
|
|
for (n = rb_first(&proc->threads); n != NULL; n = rb_next(n)) {
|
|
|
|
struct binder_thread *thread = rb_entry(n, struct binder_thread, rb_node);
|
2014-05-01 01:30:23 +09:00
|
|
|
|
2017-01-06 14:19:25 -08:00
|
|
|
thread->looper_need_return = true;
|
2011-11-30 20:18:14 +09:00
|
|
|
if (thread->looper & BINDER_LOOPER_STATE_WAITING) {
|
|
|
|
wake_up_interruptible(&thread->wait);
|
|
|
|
wake_count++;
|
|
|
|
}
|
|
|
|
}
|
2017-05-25 15:52:17 -07:00
|
|
|
binder_inner_proc_unlock(proc);
|
2011-11-30 20:18:14 +09:00
|
|
|
|
|
|
|
binder_debug(BINDER_DEBUG_OPEN_CLOSE,
|
|
|
|
"binder_flush: %d woke %d threads\n", proc->pid,
|
|
|
|
wake_count);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int binder_release(struct inode *nodp, struct file *filp)
|
|
|
|
{
|
|
|
|
struct binder_proc *proc = filp->private_data;
|
2014-05-01 01:30:23 +09:00
|
|
|
|
2009-04-28 20:57:50 -07:00
|
|
|
debugfs_remove(proc->debugfs_entry);
|
2011-11-30 20:18:14 +09:00
|
|
|
binder_defer_work(proc, BINDER_DEFERRED_RELEASE);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-03-12 11:41:59 +01:00
|
|
|
static int binder_node_release(struct binder_node *node, int refs)
|
|
|
|
{
|
|
|
|
struct binder_ref *ref;
|
|
|
|
int death = 0;
|
2017-03-21 13:06:01 -07:00
|
|
|
struct binder_proc *proc = node->proc;
|
2013-03-12 11:41:59 +01:00
|
|
|
|
2016-10-20 10:33:00 -07:00
|
|
|
binder_release_work(proc, &node->async_todo);
|
2013-03-12 11:41:59 +01:00
|
|
|
|
2017-06-08 13:45:59 -07:00
|
|
|
binder_node_lock(node);
|
2017-03-21 13:06:01 -07:00
|
|
|
binder_inner_proc_lock(proc);
|
2016-10-20 10:33:00 -07:00
|
|
|
binder_dequeue_work_ilocked(&node->work);
|
2017-05-09 11:08:05 -07:00
|
|
|
/*
|
|
|
|
* The caller must have taken a temporary ref on the node,
|
|
|
|
*/
|
|
|
|
BUG_ON(!node->tmp_refs);
|
|
|
|
if (hlist_empty(&node->refs) && node->tmp_refs == 1) {
|
2017-03-21 13:06:01 -07:00
|
|
|
binder_inner_proc_unlock(proc);
|
2017-06-08 13:45:59 -07:00
|
|
|
binder_node_unlock(node);
|
2017-03-21 13:06:01 -07:00
|
|
|
binder_free_node(node);
|
2013-03-12 11:41:59 +01:00
|
|
|
|
|
|
|
return refs;
|
|
|
|
}
|
|
|
|
|
|
|
|
node->proc = NULL;
|
|
|
|
node->local_strong_refs = 0;
|
|
|
|
node->local_weak_refs = 0;
|
2017-03-21 13:06:01 -07:00
|
|
|
binder_inner_proc_unlock(proc);
|
2016-10-17 12:33:15 -07:00
|
|
|
|
|
|
|
spin_lock(&binder_dead_nodes_lock);
|
2017-03-24 15:53:53 -07:00
|
|
|
hlist_add_head(&node->dead_node, &binder_dead_nodes);
|
2016-10-17 12:33:15 -07:00
|
|
|
spin_unlock(&binder_dead_nodes_lock);
|
2013-03-12 11:41:59 +01:00
|
|
|
|
|
|
|
hlist_for_each_entry(ref, &node->refs, node_entry) {
|
|
|
|
refs++;
|
2017-05-22 11:26:23 -07:00
|
|
|
/*
|
|
|
|
* Need the node lock to synchronize
|
|
|
|
* with new notification requests and the
|
|
|
|
* inner lock to synchronize with queued
|
|
|
|
* death notifications.
|
|
|
|
*/
|
|
|
|
binder_inner_proc_lock(ref->proc);
|
|
|
|
if (!ref->death) {
|
|
|
|
binder_inner_proc_unlock(ref->proc);
|
2014-02-17 13:58:29 -08:00
|
|
|
continue;
|
2017-05-22 11:26:23 -07:00
|
|
|
}
|
2013-03-12 11:41:59 +01:00
|
|
|
|
|
|
|
death++;
|
|
|
|
|
2017-05-22 11:26:23 -07:00
|
|
|
BUG_ON(!list_empty(&ref->death->work.entry));
|
|
|
|
ref->death->work.type = BINDER_WORK_DEAD_BINDER;
|
|
|
|
binder_enqueue_work_ilocked(&ref->death->work,
|
|
|
|
&ref->proc->todo);
|
2017-06-06 15:17:46 -07:00
|
|
|
binder_wakeup_proc_ilocked(ref->proc);
|
2016-10-20 10:33:00 -07:00
|
|
|
binder_inner_proc_unlock(ref->proc);
|
2013-03-12 11:41:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
binder_debug(BINDER_DEBUG_DEAD_BINDER,
|
|
|
|
"node %d now dead, refs %d, death %d\n",
|
|
|
|
node->debug_id, refs, death);
|
2017-06-08 13:45:59 -07:00
|
|
|
binder_node_unlock(node);
|
2017-05-09 11:08:05 -07:00
|
|
|
binder_put_node(node);
|
2013-03-12 11:41:59 +01:00
|
|
|
|
|
|
|
return refs;
|
|
|
|
}
|
|
|
|
|
2011-11-30 20:18:14 +09:00
|
|
|
static void binder_deferred_release(struct binder_proc *proc)
|
|
|
|
{
|
2016-09-30 15:51:48 +02:00
|
|
|
struct binder_context *context = proc->context;
|
2011-11-30 20:18:14 +09:00
|
|
|
struct rb_node *n;
|
2016-10-10 10:40:53 -07:00
|
|
|
int threads, nodes, incoming_refs, outgoing_refs, active_transactions;
|
2011-11-30 20:18:14 +09:00
|
|
|
|
2016-10-17 12:33:15 -07:00
|
|
|
mutex_lock(&binder_procs_lock);
|
2011-11-30 20:18:14 +09:00
|
|
|
hlist_del(&proc->proc_node);
|
2016-10-17 12:33:15 -07:00
|
|
|
mutex_unlock(&binder_procs_lock);
|
2013-03-12 11:42:00 +01:00
|
|
|
|
2016-10-17 12:33:15 -07:00
|
|
|
mutex_lock(&context->context_mgr_node_lock);
|
2016-09-30 15:51:48 +02:00
|
|
|
if (context->binder_context_mgr_node &&
|
|
|
|
context->binder_context_mgr_node->proc == proc) {
|
2011-11-30 20:18:14 +09:00
|
|
|
binder_debug(BINDER_DEBUG_DEAD_BINDER,
|
2013-03-12 11:42:02 +01:00
|
|
|
"%s: %d context_mgr_node gone\n",
|
|
|
|
__func__, proc->pid);
|
2016-09-30 15:51:48 +02:00
|
|
|
context->binder_context_mgr_node = NULL;
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
2016-10-17 12:33:15 -07:00
|
|
|
mutex_unlock(&context->context_mgr_node_lock);
|
2017-05-25 15:52:17 -07:00
|
|
|
binder_inner_proc_lock(proc);
|
2017-05-12 14:42:55 -07:00
|
|
|
/*
|
|
|
|
* Make sure proc stays alive after we
|
|
|
|
* remove all the threads
|
|
|
|
*/
|
|
|
|
proc->tmp_ref++;
|
2011-11-30 20:18:14 +09:00
|
|
|
|
2017-05-12 14:42:55 -07:00
|
|
|
proc->is_dead = true;
|
2011-11-30 20:18:14 +09:00
|
|
|
threads = 0;
|
|
|
|
active_transactions = 0;
|
|
|
|
while ((n = rb_first(&proc->threads))) {
|
2013-03-12 11:42:00 +01:00
|
|
|
struct binder_thread *thread;
|
|
|
|
|
|
|
|
thread = rb_entry(n, struct binder_thread, rb_node);
|
2017-05-25 15:52:17 -07:00
|
|
|
binder_inner_proc_unlock(proc);
|
2011-11-30 20:18:14 +09:00
|
|
|
threads++;
|
2017-05-12 14:42:55 -07:00
|
|
|
active_transactions += binder_thread_release(proc, thread);
|
2017-05-25 15:52:17 -07:00
|
|
|
binder_inner_proc_lock(proc);
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
2013-03-12 11:42:00 +01:00
|
|
|
|
2011-11-30 20:18:14 +09:00
|
|
|
nodes = 0;
|
|
|
|
incoming_refs = 0;
|
|
|
|
while ((n = rb_first(&proc->nodes))) {
|
2013-03-12 11:42:00 +01:00
|
|
|
struct binder_node *node;
|
2011-11-30 20:18:14 +09:00
|
|
|
|
2013-03-12 11:42:00 +01:00
|
|
|
node = rb_entry(n, struct binder_node, rb_node);
|
2011-11-30 20:18:14 +09:00
|
|
|
nodes++;
|
2017-05-09 11:08:05 -07:00
|
|
|
/*
|
|
|
|
* take a temporary ref on the node before
|
|
|
|
* calling binder_node_release() which will either
|
|
|
|
* kfree() the node or call binder_put_node()
|
|
|
|
*/
|
2017-06-12 12:07:26 -07:00
|
|
|
binder_inc_node_tmpref_ilocked(node);
|
2011-11-30 20:18:14 +09:00
|
|
|
rb_erase(&node->rb_node, &proc->nodes);
|
2017-06-12 12:07:26 -07:00
|
|
|
binder_inner_proc_unlock(proc);
|
2017-03-24 15:53:53 -07:00
|
|
|
incoming_refs = binder_node_release(node, incoming_refs);
|
2017-06-12 12:07:26 -07:00
|
|
|
binder_inner_proc_lock(proc);
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
2017-06-12 12:07:26 -07:00
|
|
|
binder_inner_proc_unlock(proc);
|
2013-03-12 11:42:00 +01:00
|
|
|
|
2011-11-30 20:18:14 +09:00
|
|
|
outgoing_refs = 0;
|
2016-10-20 16:43:34 -07:00
|
|
|
binder_proc_lock(proc);
|
2011-11-30 20:18:14 +09:00
|
|
|
while ((n = rb_first(&proc->refs_by_desc))) {
|
2013-03-12 11:42:00 +01:00
|
|
|
struct binder_ref *ref;
|
|
|
|
|
|
|
|
ref = rb_entry(n, struct binder_ref, rb_node_desc);
|
2011-11-30 20:18:14 +09:00
|
|
|
outgoing_refs++;
|
2016-10-20 16:43:34 -07:00
|
|
|
binder_cleanup_ref_olocked(ref);
|
|
|
|
binder_proc_unlock(proc);
|
2017-05-08 09:16:27 -07:00
|
|
|
binder_free_ref(ref);
|
2016-10-20 16:43:34 -07:00
|
|
|
binder_proc_lock(proc);
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
2016-10-20 16:43:34 -07:00
|
|
|
binder_proc_unlock(proc);
|
2011-11-30 20:18:14 +09:00
|
|
|
|
2016-10-20 10:33:00 -07:00
|
|
|
binder_release_work(proc, &proc->todo);
|
|
|
|
binder_release_work(proc, &proc->delivered_death);
|
2011-11-30 20:18:14 +09:00
|
|
|
|
|
|
|
binder_debug(BINDER_DEBUG_OPEN_CLOSE,
|
2016-10-10 10:40:53 -07:00
|
|
|
"%s: %d threads %d, nodes %d (ref %d), refs %d, active transactions %d\n",
|
2013-03-12 11:42:02 +01:00
|
|
|
__func__, proc->pid, threads, nodes, incoming_refs,
|
2016-10-10 10:40:53 -07:00
|
|
|
outgoing_refs, active_transactions);
|
2011-11-30 20:18:14 +09:00
|
|
|
|
2017-05-12 14:42:55 -07:00
|
|
|
binder_proc_dec_tmpref(proc);
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
static void binder_deferred_func(struct work_struct *work)
|
|
|
|
{
|
|
|
|
struct binder_proc *proc;
|
|
|
|
int defer;
|
2014-05-01 01:30:23 +09:00
|
|
|
|
2011-11-30 20:18:14 +09:00
|
|
|
do {
|
2017-03-24 15:53:53 -07:00
|
|
|
mutex_lock(&binder_deferred_lock);
|
|
|
|
if (!hlist_empty(&binder_deferred_list)) {
|
|
|
|
proc = hlist_entry(binder_deferred_list.first,
|
2011-11-30 20:18:14 +09:00
|
|
|
struct binder_proc, deferred_work_node);
|
|
|
|
hlist_del_init(&proc->deferred_work_node);
|
|
|
|
defer = proc->deferred_work;
|
|
|
|
proc->deferred_work = 0;
|
|
|
|
} else {
|
|
|
|
proc = NULL;
|
|
|
|
defer = 0;
|
|
|
|
}
|
2017-03-24 15:53:53 -07:00
|
|
|
mutex_unlock(&binder_deferred_lock);
|
2011-11-30 20:18:14 +09:00
|
|
|
|
|
|
|
if (defer & BINDER_DEFERRED_FLUSH)
|
|
|
|
binder_deferred_flush(proc);
|
|
|
|
|
|
|
|
if (defer & BINDER_DEFERRED_RELEASE)
|
|
|
|
binder_deferred_release(proc); /* frees proc */
|
|
|
|
} while (proc);
|
|
|
|
}
|
2017-03-24 15:53:53 -07:00
|
|
|
static DECLARE_WORK(binder_deferred_work, binder_deferred_func);
|
2011-11-30 20:18:14 +09:00
|
|
|
|
|
|
|
static void
|
|
|
|
binder_defer_work(struct binder_proc *proc, enum binder_deferred_state defer)
|
|
|
|
{
|
2017-03-24 15:53:53 -07:00
|
|
|
mutex_lock(&binder_deferred_lock);
|
2011-11-30 20:18:14 +09:00
|
|
|
proc->deferred_work |= defer;
|
|
|
|
if (hlist_unhashed(&proc->deferred_work_node)) {
|
|
|
|
hlist_add_head(&proc->deferred_work_node,
|
2017-03-24 15:53:53 -07:00
|
|
|
&binder_deferred_list);
|
|
|
|
queue_work(binder_deferred_workqueue, &binder_deferred_work);
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
2017-03-24 15:53:53 -07:00
|
|
|
mutex_unlock(&binder_deferred_lock);
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
|
|
|
|
2017-04-21 14:32:11 -07:00
|
|
|
static void print_binder_transaction_ilocked(struct seq_file *m,
|
|
|
|
struct binder_proc *proc,
|
|
|
|
const char *prefix,
|
|
|
|
struct binder_transaction *t)
|
2009-04-28 20:57:50 -07:00
|
|
|
{
|
2017-04-21 14:32:11 -07:00
|
|
|
struct binder_proc *to_proc;
|
|
|
|
struct binder_buffer *buffer = t->buffer;
|
|
|
|
|
2017-05-12 14:42:55 -07:00
|
|
|
spin_lock(&t->lock);
|
2017-04-21 14:32:11 -07:00
|
|
|
to_proc = t->to_proc;
|
2009-04-28 20:57:50 -07:00
|
|
|
seq_printf(m,
|
2017-06-06 17:04:42 -07:00
|
|
|
"%s %d: %p from %d:%d to %d:%d code %x flags %x pri %d:%d r%d",
|
2009-04-28 20:57:50 -07:00
|
|
|
prefix, t->debug_id, t,
|
|
|
|
t->from ? t->from->proc->pid : 0,
|
|
|
|
t->from ? t->from->pid : 0,
|
2017-04-21 14:32:11 -07:00
|
|
|
to_proc ? to_proc->pid : 0,
|
2009-04-28 20:57:50 -07:00
|
|
|
t->to_thread ? t->to_thread->pid : 0,
|
2017-06-06 17:04:42 -07:00
|
|
|
t->code, t->flags, t->priority.sched_policy,
|
|
|
|
t->priority.prio, t->need_reply);
|
2017-05-12 14:42:55 -07:00
|
|
|
spin_unlock(&t->lock);
|
|
|
|
|
2017-04-21 14:32:11 -07:00
|
|
|
if (proc != to_proc) {
|
|
|
|
/*
|
|
|
|
* Can only safely deref buffer if we are holding the
|
|
|
|
* correct proc inner lock for this node
|
|
|
|
*/
|
|
|
|
seq_puts(m, "\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (buffer == NULL) {
|
2009-04-28 20:57:50 -07:00
|
|
|
seq_puts(m, " buffer free\n");
|
|
|
|
return;
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
2017-04-21 14:32:11 -07:00
|
|
|
if (buffer->target_node)
|
|
|
|
seq_printf(m, " node %d", buffer->target_node->debug_id);
|
2009-04-28 20:57:50 -07:00
|
|
|
seq_printf(m, " size %zd:%zd data %p\n",
|
|
|
|
buffer->data_size, buffer->offsets_size,
|
2017-04-21 14:32:11 -07:00
|
|
|
buffer->data);
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
|
|
|
|
2017-04-21 14:32:11 -07:00
|
|
|
static void print_binder_work_ilocked(struct seq_file *m,
|
|
|
|
struct binder_proc *proc,
|
|
|
|
const char *prefix,
|
|
|
|
const char *transaction_prefix,
|
|
|
|
struct binder_work *w)
|
2011-11-30 20:18:14 +09:00
|
|
|
{
|
|
|
|
struct binder_node *node;
|
|
|
|
struct binder_transaction *t;
|
|
|
|
|
|
|
|
switch (w->type) {
|
|
|
|
case BINDER_WORK_TRANSACTION:
|
|
|
|
t = container_of(w, struct binder_transaction, work);
|
2017-04-21 14:32:11 -07:00
|
|
|
print_binder_transaction_ilocked(
|
|
|
|
m, proc, transaction_prefix, t);
|
2011-11-30 20:18:14 +09:00
|
|
|
break;
|
2017-04-21 17:35:12 -07:00
|
|
|
case BINDER_WORK_RETURN_ERROR: {
|
|
|
|
struct binder_error *e = container_of(
|
|
|
|
w, struct binder_error, work);
|
|
|
|
|
|
|
|
seq_printf(m, "%stransaction error: %u\n",
|
|
|
|
prefix, e->cmd);
|
|
|
|
} break;
|
2011-11-30 20:18:14 +09:00
|
|
|
case BINDER_WORK_TRANSACTION_COMPLETE:
|
2009-04-28 20:57:50 -07:00
|
|
|
seq_printf(m, "%stransaction complete\n", prefix);
|
2011-11-30 20:18:14 +09:00
|
|
|
break;
|
|
|
|
case BINDER_WORK_NODE:
|
|
|
|
node = container_of(w, struct binder_node, work);
|
2014-02-21 14:40:26 -08:00
|
|
|
seq_printf(m, "%snode work %d: u%016llx c%016llx\n",
|
|
|
|
prefix, node->debug_id,
|
|
|
|
(u64)node->ptr, (u64)node->cookie);
|
2011-11-30 20:18:14 +09:00
|
|
|
break;
|
|
|
|
case BINDER_WORK_DEAD_BINDER:
|
2009-04-28 20:57:50 -07:00
|
|
|
seq_printf(m, "%shas dead binder\n", prefix);
|
2011-11-30 20:18:14 +09:00
|
|
|
break;
|
|
|
|
case BINDER_WORK_DEAD_BINDER_AND_CLEAR:
|
2009-04-28 20:57:50 -07:00
|
|
|
seq_printf(m, "%shas cleared dead binder\n", prefix);
|
2011-11-30 20:18:14 +09:00
|
|
|
break;
|
|
|
|
case BINDER_WORK_CLEAR_DEATH_NOTIFICATION:
|
2009-04-28 20:57:50 -07:00
|
|
|
seq_printf(m, "%shas cleared death notification\n", prefix);
|
2011-11-30 20:18:14 +09:00
|
|
|
break;
|
|
|
|
default:
|
2009-04-28 20:57:50 -07:00
|
|
|
seq_printf(m, "%sunknown work: type %d\n", prefix, w->type);
|
2011-11-30 20:18:14 +09:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-20 10:33:00 -07:00
|
|
|
static void print_binder_thread_ilocked(struct seq_file *m,
|
|
|
|
struct binder_thread *thread,
|
|
|
|
int print_always)
|
2011-11-30 20:18:14 +09:00
|
|
|
{
|
|
|
|
struct binder_transaction *t;
|
|
|
|
struct binder_work *w;
|
2009-04-28 20:57:50 -07:00
|
|
|
size_t start_pos = m->count;
|
|
|
|
size_t header_pos;
|
2011-11-30 20:18:14 +09:00
|
|
|
|
2017-05-12 14:42:55 -07:00
|
|
|
seq_printf(m, " thread %d: l %02x need_return %d tr %d\n",
|
2017-01-06 14:19:25 -08:00
|
|
|
thread->pid, thread->looper,
|
2017-05-12 14:42:55 -07:00
|
|
|
thread->looper_need_return,
|
|
|
|
atomic_read(&thread->tmp_ref));
|
2009-04-28 20:57:50 -07:00
|
|
|
header_pos = m->count;
|
2011-11-30 20:18:14 +09:00
|
|
|
t = thread->transaction_stack;
|
|
|
|
while (t) {
|
|
|
|
if (t->from == thread) {
|
2017-04-21 14:32:11 -07:00
|
|
|
print_binder_transaction_ilocked(m, thread->proc,
|
|
|
|
" outgoing transaction", t);
|
2011-11-30 20:18:14 +09:00
|
|
|
t = t->from_parent;
|
|
|
|
} else if (t->to_thread == thread) {
|
2017-04-21 14:32:11 -07:00
|
|
|
print_binder_transaction_ilocked(m, thread->proc,
|
2009-04-28 20:57:50 -07:00
|
|
|
" incoming transaction", t);
|
2011-11-30 20:18:14 +09:00
|
|
|
t = t->to_parent;
|
|
|
|
} else {
|
2017-04-21 14:32:11 -07:00
|
|
|
print_binder_transaction_ilocked(m, thread->proc,
|
|
|
|
" bad transaction", t);
|
2011-11-30 20:18:14 +09:00
|
|
|
t = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
list_for_each_entry(w, &thread->todo, entry) {
|
2017-04-21 14:32:11 -07:00
|
|
|
print_binder_work_ilocked(m, thread->proc, " ",
|
2016-10-20 10:33:00 -07:00
|
|
|
" pending transaction", w);
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
2009-04-28 20:57:50 -07:00
|
|
|
if (!print_always && m->count == header_pos)
|
|
|
|
m->count = start_pos;
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
|
|
|
|
2017-06-12 12:07:26 -07:00
|
|
|
static void print_binder_node_nilocked(struct seq_file *m,
|
|
|
|
struct binder_node *node)
|
2011-11-30 20:18:14 +09:00
|
|
|
{
|
|
|
|
struct binder_ref *ref;
|
|
|
|
struct binder_work *w;
|
|
|
|
int count;
|
|
|
|
|
|
|
|
count = 0;
|
hlist: drop the node parameter from iterators
I'm not sure why, but the hlist for each entry iterators were conceived
list_for_each_entry(pos, head, member)
The hlist ones were greedy and wanted an extra parameter:
hlist_for_each_entry(tpos, pos, head, member)
Why did they need an extra pos parameter? I'm not quite sure. Not only
they don't really need it, it also prevents the iterator from looking
exactly like the list iterator, which is unfortunate.
Besides the semantic patch, there was some manual work required:
- Fix up the actual hlist iterators in linux/list.h
- Fix up the declaration of other iterators based on the hlist ones.
- A very small amount of places were using the 'node' parameter, this
was modified to use 'obj->member' instead.
- Coccinelle didn't handle the hlist_for_each_entry_safe iterator
properly, so those had to be fixed up manually.
The semantic patch which is mostly the work of Peter Senna Tschudin is here:
@@
iterator name hlist_for_each_entry, hlist_for_each_entry_continue, hlist_for_each_entry_from, hlist_for_each_entry_rcu, hlist_for_each_entry_rcu_bh, hlist_for_each_entry_continue_rcu_bh, for_each_busy_worker, ax25_uid_for_each, ax25_for_each, inet_bind_bucket_for_each, sctp_for_each_hentry, sk_for_each, sk_for_each_rcu, sk_for_each_from, sk_for_each_safe, sk_for_each_bound, hlist_for_each_entry_safe, hlist_for_each_entry_continue_rcu, nr_neigh_for_each, nr_neigh_for_each_safe, nr_node_for_each, nr_node_for_each_safe, for_each_gfn_indirect_valid_sp, for_each_gfn_sp, for_each_host;
type T;
expression a,c,d,e;
identifier b;
statement S;
@@
-T b;
<+... when != b
(
hlist_for_each_entry(a,
- b,
c, d) S
|
hlist_for_each_entry_continue(a,
- b,
c) S
|
hlist_for_each_entry_from(a,
- b,
c) S
|
hlist_for_each_entry_rcu(a,
- b,
c, d) S
|
hlist_for_each_entry_rcu_bh(a,
- b,
c, d) S
|
hlist_for_each_entry_continue_rcu_bh(a,
- b,
c) S
|
for_each_busy_worker(a, c,
- b,
d) S
|
ax25_uid_for_each(a,
- b,
c) S
|
ax25_for_each(a,
- b,
c) S
|
inet_bind_bucket_for_each(a,
- b,
c) S
|
sctp_for_each_hentry(a,
- b,
c) S
|
sk_for_each(a,
- b,
c) S
|
sk_for_each_rcu(a,
- b,
c) S
|
sk_for_each_from
-(a, b)
+(a)
S
+ sk_for_each_from(a) S
|
sk_for_each_safe(a,
- b,
c, d) S
|
sk_for_each_bound(a,
- b,
c) S
|
hlist_for_each_entry_safe(a,
- b,
c, d, e) S
|
hlist_for_each_entry_continue_rcu(a,
- b,
c) S
|
nr_neigh_for_each(a,
- b,
c) S
|
nr_neigh_for_each_safe(a,
- b,
c, d) S
|
nr_node_for_each(a,
- b,
c) S
|
nr_node_for_each_safe(a,
- b,
c, d) S
|
- for_each_gfn_sp(a, c, d, b) S
+ for_each_gfn_sp(a, c, d) S
|
- for_each_gfn_indirect_valid_sp(a, c, d, b) S
+ for_each_gfn_indirect_valid_sp(a, c, d) S
|
for_each_host(a,
- b,
c) S
|
for_each_host_safe(a,
- b,
c, d) S
|
for_each_mesh_entry(a,
- b,
c, d) S
)
...+>
[akpm@linux-foundation.org: drop bogus change from net/ipv4/raw.c]
[akpm@linux-foundation.org: drop bogus hunk from net/ipv6/raw.c]
[akpm@linux-foundation.org: checkpatch fixes]
[akpm@linux-foundation.org: fix warnings]
[akpm@linux-foudnation.org: redo intrusive kvm changes]
Tested-by: Peter Senna Tschudin <peter.senna@gmail.com>
Acked-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
Cc: Wu Fengguang <fengguang.wu@intel.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-02-27 17:06:00 -08:00
|
|
|
hlist_for_each_entry(ref, &node->refs, node_entry)
|
2011-11-30 20:18:14 +09:00
|
|
|
count++;
|
|
|
|
|
2017-06-07 09:29:14 -07:00
|
|
|
seq_printf(m, " node %d: u%016llx c%016llx pri %d:%d hs %d hw %d ls %d lw %d is %d iw %d tr %d",
|
2014-02-21 14:40:26 -08:00
|
|
|
node->debug_id, (u64)node->ptr, (u64)node->cookie,
|
2017-06-07 09:29:14 -07:00
|
|
|
node->sched_policy, node->min_priority,
|
2009-04-28 20:57:50 -07:00
|
|
|
node->has_strong_ref, node->has_weak_ref,
|
|
|
|
node->local_strong_refs, node->local_weak_refs,
|
2017-05-09 11:08:05 -07:00
|
|
|
node->internal_strong_refs, count, node->tmp_refs);
|
2011-11-30 20:18:14 +09:00
|
|
|
if (count) {
|
2009-04-28 20:57:50 -07:00
|
|
|
seq_puts(m, " proc");
|
hlist: drop the node parameter from iterators
I'm not sure why, but the hlist for each entry iterators were conceived
list_for_each_entry(pos, head, member)
The hlist ones were greedy and wanted an extra parameter:
hlist_for_each_entry(tpos, pos, head, member)
Why did they need an extra pos parameter? I'm not quite sure. Not only
they don't really need it, it also prevents the iterator from looking
exactly like the list iterator, which is unfortunate.
Besides the semantic patch, there was some manual work required:
- Fix up the actual hlist iterators in linux/list.h
- Fix up the declaration of other iterators based on the hlist ones.
- A very small amount of places were using the 'node' parameter, this
was modified to use 'obj->member' instead.
- Coccinelle didn't handle the hlist_for_each_entry_safe iterator
properly, so those had to be fixed up manually.
The semantic patch which is mostly the work of Peter Senna Tschudin is here:
@@
iterator name hlist_for_each_entry, hlist_for_each_entry_continue, hlist_for_each_entry_from, hlist_for_each_entry_rcu, hlist_for_each_entry_rcu_bh, hlist_for_each_entry_continue_rcu_bh, for_each_busy_worker, ax25_uid_for_each, ax25_for_each, inet_bind_bucket_for_each, sctp_for_each_hentry, sk_for_each, sk_for_each_rcu, sk_for_each_from, sk_for_each_safe, sk_for_each_bound, hlist_for_each_entry_safe, hlist_for_each_entry_continue_rcu, nr_neigh_for_each, nr_neigh_for_each_safe, nr_node_for_each, nr_node_for_each_safe, for_each_gfn_indirect_valid_sp, for_each_gfn_sp, for_each_host;
type T;
expression a,c,d,e;
identifier b;
statement S;
@@
-T b;
<+... when != b
(
hlist_for_each_entry(a,
- b,
c, d) S
|
hlist_for_each_entry_continue(a,
- b,
c) S
|
hlist_for_each_entry_from(a,
- b,
c) S
|
hlist_for_each_entry_rcu(a,
- b,
c, d) S
|
hlist_for_each_entry_rcu_bh(a,
- b,
c, d) S
|
hlist_for_each_entry_continue_rcu_bh(a,
- b,
c) S
|
for_each_busy_worker(a, c,
- b,
d) S
|
ax25_uid_for_each(a,
- b,
c) S
|
ax25_for_each(a,
- b,
c) S
|
inet_bind_bucket_for_each(a,
- b,
c) S
|
sctp_for_each_hentry(a,
- b,
c) S
|
sk_for_each(a,
- b,
c) S
|
sk_for_each_rcu(a,
- b,
c) S
|
sk_for_each_from
-(a, b)
+(a)
S
+ sk_for_each_from(a) S
|
sk_for_each_safe(a,
- b,
c, d) S
|
sk_for_each_bound(a,
- b,
c) S
|
hlist_for_each_entry_safe(a,
- b,
c, d, e) S
|
hlist_for_each_entry_continue_rcu(a,
- b,
c) S
|
nr_neigh_for_each(a,
- b,
c) S
|
nr_neigh_for_each_safe(a,
- b,
c, d) S
|
nr_node_for_each(a,
- b,
c) S
|
nr_node_for_each_safe(a,
- b,
c, d) S
|
- for_each_gfn_sp(a, c, d, b) S
+ for_each_gfn_sp(a, c, d) S
|
- for_each_gfn_indirect_valid_sp(a, c, d, b) S
+ for_each_gfn_indirect_valid_sp(a, c, d) S
|
for_each_host(a,
- b,
c) S
|
for_each_host_safe(a,
- b,
c, d) S
|
for_each_mesh_entry(a,
- b,
c, d) S
)
...+>
[akpm@linux-foundation.org: drop bogus change from net/ipv4/raw.c]
[akpm@linux-foundation.org: drop bogus hunk from net/ipv6/raw.c]
[akpm@linux-foundation.org: checkpatch fixes]
[akpm@linux-foundation.org: fix warnings]
[akpm@linux-foudnation.org: redo intrusive kvm changes]
Tested-by: Peter Senna Tschudin <peter.senna@gmail.com>
Acked-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
Cc: Wu Fengguang <fengguang.wu@intel.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-02-27 17:06:00 -08:00
|
|
|
hlist_for_each_entry(ref, &node->refs, node_entry)
|
2009-04-28 20:57:50 -07:00
|
|
|
seq_printf(m, " %d", ref->proc->pid);
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
2009-04-28 20:57:50 -07:00
|
|
|
seq_puts(m, "\n");
|
2016-10-20 10:33:00 -07:00
|
|
|
if (node->proc) {
|
|
|
|
list_for_each_entry(w, &node->async_todo, entry)
|
2017-04-21 14:32:11 -07:00
|
|
|
print_binder_work_ilocked(m, node->proc, " ",
|
2016-10-20 10:33:00 -07:00
|
|
|
" pending async transaction", w);
|
|
|
|
}
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
|
|
|
|
2016-10-20 16:43:34 -07:00
|
|
|
static void print_binder_ref_olocked(struct seq_file *m,
|
|
|
|
struct binder_ref *ref)
|
2011-11-30 20:18:14 +09:00
|
|
|
{
|
2017-06-08 13:45:59 -07:00
|
|
|
binder_node_lock(ref->node);
|
2016-08-17 16:00:08 -07:00
|
|
|
seq_printf(m, " ref %d: desc %d %snode %d s %d w %d d %pK\n",
|
2017-05-08 09:16:27 -07:00
|
|
|
ref->data.debug_id, ref->data.desc,
|
|
|
|
ref->node->proc ? "" : "dead ",
|
|
|
|
ref->node->debug_id, ref->data.strong,
|
|
|
|
ref->data.weak, ref->death);
|
2017-06-08 13:45:59 -07:00
|
|
|
binder_node_unlock(ref->node);
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
|
|
|
|
2009-04-28 20:57:50 -07:00
|
|
|
static void print_binder_proc(struct seq_file *m,
|
|
|
|
struct binder_proc *proc, int print_all)
|
2011-11-30 20:18:14 +09:00
|
|
|
{
|
|
|
|
struct binder_work *w;
|
|
|
|
struct rb_node *n;
|
2009-04-28 20:57:50 -07:00
|
|
|
size_t start_pos = m->count;
|
|
|
|
size_t header_pos;
|
2017-06-12 12:07:26 -07:00
|
|
|
struct binder_node *last_node = NULL;
|
2009-04-28 20:57:50 -07:00
|
|
|
|
|
|
|
seq_printf(m, "proc %d\n", proc->pid);
|
2016-10-17 15:17:31 +02:00
|
|
|
seq_printf(m, "context %s\n", proc->context->name);
|
2009-04-28 20:57:50 -07:00
|
|
|
header_pos = m->count;
|
|
|
|
|
2016-10-20 10:33:00 -07:00
|
|
|
binder_inner_proc_lock(proc);
|
2009-04-28 20:57:50 -07:00
|
|
|
for (n = rb_first(&proc->threads); n != NULL; n = rb_next(n))
|
2016-10-20 10:33:00 -07:00
|
|
|
print_binder_thread_ilocked(m, rb_entry(n, struct binder_thread,
|
2009-04-28 20:57:50 -07:00
|
|
|
rb_node), print_all);
|
2017-06-12 12:07:26 -07:00
|
|
|
|
2009-04-28 20:57:50 -07:00
|
|
|
for (n = rb_first(&proc->nodes); n != NULL; n = rb_next(n)) {
|
2011-11-30 20:18:14 +09:00
|
|
|
struct binder_node *node = rb_entry(n, struct binder_node,
|
|
|
|
rb_node);
|
2017-06-12 12:07:26 -07:00
|
|
|
/*
|
|
|
|
* take a temporary reference on the node so it
|
|
|
|
* survives and isn't removed from the tree
|
|
|
|
* while we print it.
|
|
|
|
*/
|
|
|
|
binder_inc_node_tmpref_ilocked(node);
|
|
|
|
/* Need to drop inner lock to take node lock */
|
|
|
|
binder_inner_proc_unlock(proc);
|
|
|
|
if (last_node)
|
|
|
|
binder_put_node(last_node);
|
|
|
|
binder_node_inner_lock(node);
|
|
|
|
print_binder_node_nilocked(m, node);
|
|
|
|
binder_node_inner_unlock(node);
|
|
|
|
last_node = node;
|
|
|
|
binder_inner_proc_lock(proc);
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
2017-06-12 12:07:26 -07:00
|
|
|
binder_inner_proc_unlock(proc);
|
|
|
|
if (last_node)
|
|
|
|
binder_put_node(last_node);
|
|
|
|
|
2011-11-30 20:18:14 +09:00
|
|
|
if (print_all) {
|
2016-10-20 16:43:34 -07:00
|
|
|
binder_proc_lock(proc);
|
2011-11-30 20:18:14 +09:00
|
|
|
for (n = rb_first(&proc->refs_by_desc);
|
2009-04-28 20:57:50 -07:00
|
|
|
n != NULL;
|
2011-11-30 20:18:14 +09:00
|
|
|
n = rb_next(n))
|
2016-10-20 16:43:34 -07:00
|
|
|
print_binder_ref_olocked(m, rb_entry(n,
|
|
|
|
struct binder_ref,
|
|
|
|
rb_node_desc));
|
|
|
|
binder_proc_unlock(proc);
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
2016-10-10 10:40:53 -07:00
|
|
|
binder_alloc_print_allocated(m, &proc->alloc);
|
2016-10-20 10:33:00 -07:00
|
|
|
binder_inner_proc_lock(proc);
|
2009-04-28 20:57:50 -07:00
|
|
|
list_for_each_entry(w, &proc->todo, entry)
|
2017-04-21 14:32:11 -07:00
|
|
|
print_binder_work_ilocked(m, proc, " ",
|
|
|
|
" pending transaction", w);
|
2011-11-30 20:18:14 +09:00
|
|
|
list_for_each_entry(w, &proc->delivered_death, entry) {
|
2009-04-28 20:57:50 -07:00
|
|
|
seq_puts(m, " has delivered dead binder\n");
|
2011-11-30 20:18:14 +09:00
|
|
|
break;
|
|
|
|
}
|
2016-10-20 10:33:00 -07:00
|
|
|
binder_inner_proc_unlock(proc);
|
2009-04-28 20:57:50 -07:00
|
|
|
if (!print_all && m->count == header_pos)
|
|
|
|
m->count = start_pos;
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
|
|
|
|
2012-12-22 09:00:45 +10:00
|
|
|
static const char * const binder_return_strings[] = {
|
2011-11-30 20:18:14 +09:00
|
|
|
"BR_ERROR",
|
|
|
|
"BR_OK",
|
|
|
|
"BR_TRANSACTION",
|
|
|
|
"BR_REPLY",
|
|
|
|
"BR_ACQUIRE_RESULT",
|
|
|
|
"BR_DEAD_REPLY",
|
|
|
|
"BR_TRANSACTION_COMPLETE",
|
|
|
|
"BR_INCREFS",
|
|
|
|
"BR_ACQUIRE",
|
|
|
|
"BR_RELEASE",
|
|
|
|
"BR_DECREFS",
|
|
|
|
"BR_ATTEMPT_ACQUIRE",
|
|
|
|
"BR_NOOP",
|
|
|
|
"BR_SPAWN_LOOPER",
|
|
|
|
"BR_FINISHED",
|
|
|
|
"BR_DEAD_BINDER",
|
|
|
|
"BR_CLEAR_DEATH_NOTIFICATION_DONE",
|
|
|
|
"BR_FAILED_REPLY"
|
|
|
|
};
|
|
|
|
|
2012-12-22 09:00:45 +10:00
|
|
|
static const char * const binder_command_strings[] = {
|
2011-11-30 20:18:14 +09:00
|
|
|
"BC_TRANSACTION",
|
|
|
|
"BC_REPLY",
|
|
|
|
"BC_ACQUIRE_RESULT",
|
|
|
|
"BC_FREE_BUFFER",
|
|
|
|
"BC_INCREFS",
|
|
|
|
"BC_ACQUIRE",
|
|
|
|
"BC_RELEASE",
|
|
|
|
"BC_DECREFS",
|
|
|
|
"BC_INCREFS_DONE",
|
|
|
|
"BC_ACQUIRE_DONE",
|
|
|
|
"BC_ATTEMPT_ACQUIRE",
|
|
|
|
"BC_REGISTER_LOOPER",
|
|
|
|
"BC_ENTER_LOOPER",
|
|
|
|
"BC_EXIT_LOOPER",
|
|
|
|
"BC_REQUEST_DEATH_NOTIFICATION",
|
|
|
|
"BC_CLEAR_DEATH_NOTIFICATION",
|
2016-09-30 14:10:07 +02:00
|
|
|
"BC_DEAD_BINDER_DONE",
|
|
|
|
"BC_TRANSACTION_SG",
|
|
|
|
"BC_REPLY_SG",
|
2011-11-30 20:18:14 +09:00
|
|
|
};
|
|
|
|
|
2012-12-22 09:00:45 +10:00
|
|
|
static const char * const binder_objstat_strings[] = {
|
2011-11-30 20:18:14 +09:00
|
|
|
"proc",
|
|
|
|
"thread",
|
|
|
|
"node",
|
|
|
|
"ref",
|
|
|
|
"death",
|
|
|
|
"transaction",
|
|
|
|
"transaction_complete"
|
|
|
|
};
|
|
|
|
|
2009-04-28 20:57:50 -07:00
|
|
|
static void print_binder_stats(struct seq_file *m, const char *prefix,
|
2017-03-24 15:53:53 -07:00
|
|
|
struct binder_stats *stats)
|
2011-11-30 20:18:14 +09:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
BUILD_BUG_ON(ARRAY_SIZE(stats->bc) !=
|
2009-04-28 20:57:50 -07:00
|
|
|
ARRAY_SIZE(binder_command_strings));
|
2011-11-30 20:18:14 +09:00
|
|
|
for (i = 0; i < ARRAY_SIZE(stats->bc); i++) {
|
2016-10-13 16:36:15 -07:00
|
|
|
int temp = atomic_read(&stats->bc[i]);
|
|
|
|
|
|
|
|
if (temp)
|
2009-04-28 20:57:50 -07:00
|
|
|
seq_printf(m, "%s%s: %d\n", prefix,
|
2016-10-13 16:36:15 -07:00
|
|
|
binder_command_strings[i], temp);
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
BUILD_BUG_ON(ARRAY_SIZE(stats->br) !=
|
2009-04-28 20:57:50 -07:00
|
|
|
ARRAY_SIZE(binder_return_strings));
|
2011-11-30 20:18:14 +09:00
|
|
|
for (i = 0; i < ARRAY_SIZE(stats->br); i++) {
|
2016-10-13 16:36:15 -07:00
|
|
|
int temp = atomic_read(&stats->br[i]);
|
|
|
|
|
|
|
|
if (temp)
|
2009-04-28 20:57:50 -07:00
|
|
|
seq_printf(m, "%s%s: %d\n", prefix,
|
2016-10-13 16:36:15 -07:00
|
|
|
binder_return_strings[i], temp);
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
|
|
|
|
2017-03-24 15:53:53 -07:00
|
|
|
BUILD_BUG_ON(ARRAY_SIZE(stats->obj_created) !=
|
2009-04-28 20:57:50 -07:00
|
|
|
ARRAY_SIZE(binder_objstat_strings));
|
2017-03-24 15:53:53 -07:00
|
|
|
BUILD_BUG_ON(ARRAY_SIZE(stats->obj_created) !=
|
|
|
|
ARRAY_SIZE(stats->obj_deleted));
|
|
|
|
for (i = 0; i < ARRAY_SIZE(stats->obj_created); i++) {
|
2016-10-13 16:36:15 -07:00
|
|
|
int created = atomic_read(&stats->obj_created[i]);
|
|
|
|
int deleted = atomic_read(&stats->obj_deleted[i]);
|
|
|
|
|
|
|
|
if (created || deleted)
|
|
|
|
seq_printf(m, "%s%s: active %d total %d\n",
|
|
|
|
prefix,
|
2017-03-24 15:53:53 -07:00
|
|
|
binder_objstat_strings[i],
|
2016-10-13 16:36:15 -07:00
|
|
|
created - deleted,
|
|
|
|
created);
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-28 20:57:50 -07:00
|
|
|
static void print_binder_proc_stats(struct seq_file *m,
|
|
|
|
struct binder_proc *proc)
|
2011-11-30 20:18:14 +09:00
|
|
|
{
|
|
|
|
struct binder_work *w;
|
2017-06-02 11:15:44 -07:00
|
|
|
struct binder_thread *thread;
|
2011-11-30 20:18:14 +09:00
|
|
|
struct rb_node *n;
|
2017-06-02 11:15:44 -07:00
|
|
|
int count, strong, weak, ready_threads;
|
2017-05-25 15:52:17 -07:00
|
|
|
size_t free_async_space =
|
|
|
|
binder_alloc_get_free_async_space(&proc->alloc);
|
2011-11-30 20:18:14 +09:00
|
|
|
|
2009-04-28 20:57:50 -07:00
|
|
|
seq_printf(m, "proc %d\n", proc->pid);
|
2016-10-17 15:17:31 +02:00
|
|
|
seq_printf(m, "context %s\n", proc->context->name);
|
2011-11-30 20:18:14 +09:00
|
|
|
count = 0;
|
2017-06-02 11:15:44 -07:00
|
|
|
ready_threads = 0;
|
2017-05-25 15:52:17 -07:00
|
|
|
binder_inner_proc_lock(proc);
|
2011-11-30 20:18:14 +09:00
|
|
|
for (n = rb_first(&proc->threads); n != NULL; n = rb_next(n))
|
|
|
|
count++;
|
2017-06-02 11:15:44 -07:00
|
|
|
|
|
|
|
list_for_each_entry(thread, &proc->waiting_threads, waiting_thread_node)
|
|
|
|
ready_threads++;
|
|
|
|
|
2009-04-28 20:57:50 -07:00
|
|
|
seq_printf(m, " threads: %d\n", count);
|
|
|
|
seq_printf(m, " requested threads: %d+%d/%d\n"
|
2011-11-30 20:18:14 +09:00
|
|
|
" ready threads %d\n"
|
|
|
|
" free async space %zd\n", proc->requested_threads,
|
|
|
|
proc->requested_threads_started, proc->max_threads,
|
2017-06-02 11:15:44 -07:00
|
|
|
ready_threads,
|
2017-05-25 15:52:17 -07:00
|
|
|
free_async_space);
|
2011-11-30 20:18:14 +09:00
|
|
|
count = 0;
|
|
|
|
for (n = rb_first(&proc->nodes); n != NULL; n = rb_next(n))
|
|
|
|
count++;
|
2017-06-12 12:07:26 -07:00
|
|
|
binder_inner_proc_unlock(proc);
|
2009-04-28 20:57:50 -07:00
|
|
|
seq_printf(m, " nodes: %d\n", count);
|
2011-11-30 20:18:14 +09:00
|
|
|
count = 0;
|
|
|
|
strong = 0;
|
|
|
|
weak = 0;
|
2016-10-20 16:43:34 -07:00
|
|
|
binder_proc_lock(proc);
|
2011-11-30 20:18:14 +09:00
|
|
|
for (n = rb_first(&proc->refs_by_desc); n != NULL; n = rb_next(n)) {
|
|
|
|
struct binder_ref *ref = rb_entry(n, struct binder_ref,
|
|
|
|
rb_node_desc);
|
|
|
|
count++;
|
2017-05-08 09:16:27 -07:00
|
|
|
strong += ref->data.strong;
|
|
|
|
weak += ref->data.weak;
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
2016-10-20 16:43:34 -07:00
|
|
|
binder_proc_unlock(proc);
|
2009-04-28 20:57:50 -07:00
|
|
|
seq_printf(m, " refs: %d s %d w %d\n", count, strong, weak);
|
2011-11-30 20:18:14 +09:00
|
|
|
|
2016-10-10 10:40:53 -07:00
|
|
|
count = binder_alloc_get_allocated_count(&proc->alloc);
|
2009-04-28 20:57:50 -07:00
|
|
|
seq_printf(m, " buffers: %d\n", count);
|
2011-11-30 20:18:14 +09:00
|
|
|
|
2017-08-22 17:26:57 -07:00
|
|
|
binder_alloc_print_pages(m, &proc->alloc);
|
|
|
|
|
2011-11-30 20:18:14 +09:00
|
|
|
count = 0;
|
2016-10-20 10:33:00 -07:00
|
|
|
binder_inner_proc_lock(proc);
|
2011-11-30 20:18:14 +09:00
|
|
|
list_for_each_entry(w, &proc->todo, entry) {
|
2016-10-20 10:33:00 -07:00
|
|
|
if (w->type == BINDER_WORK_TRANSACTION)
|
2011-11-30 20:18:14 +09:00
|
|
|
count++;
|
|
|
|
}
|
2016-10-20 10:33:00 -07:00
|
|
|
binder_inner_proc_unlock(proc);
|
2009-04-28 20:57:50 -07:00
|
|
|
seq_printf(m, " pending transactions: %d\n", count);
|
2011-11-30 20:18:14 +09:00
|
|
|
|
2017-03-24 15:53:53 -07:00
|
|
|
print_binder_stats(m, " ", &proc->stats);
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-28 20:57:50 -07:00
|
|
|
static int binder_state_show(struct seq_file *m, void *unused)
|
2011-11-30 20:18:14 +09:00
|
|
|
{
|
|
|
|
struct binder_proc *proc;
|
|
|
|
struct binder_node *node;
|
2017-06-08 13:45:59 -07:00
|
|
|
struct binder_node *last_node = NULL;
|
2011-11-30 20:18:14 +09:00
|
|
|
|
2009-04-28 20:57:50 -07:00
|
|
|
seq_puts(m, "binder state:\n");
|
2011-11-30 20:18:14 +09:00
|
|
|
|
2016-10-17 12:33:15 -07:00
|
|
|
spin_lock(&binder_dead_nodes_lock);
|
2017-03-24 15:53:53 -07:00
|
|
|
if (!hlist_empty(&binder_dead_nodes))
|
|
|
|
seq_puts(m, "dead nodes:\n");
|
2017-06-08 13:45:59 -07:00
|
|
|
hlist_for_each_entry(node, &binder_dead_nodes, dead_node) {
|
|
|
|
/*
|
|
|
|
* take a temporary reference on the node so it
|
|
|
|
* survives and isn't removed from the list
|
|
|
|
* while we print it.
|
|
|
|
*/
|
|
|
|
node->tmp_refs++;
|
|
|
|
spin_unlock(&binder_dead_nodes_lock);
|
|
|
|
if (last_node)
|
|
|
|
binder_put_node(last_node);
|
|
|
|
binder_node_lock(node);
|
2017-06-12 12:07:26 -07:00
|
|
|
print_binder_node_nilocked(m, node);
|
2017-06-08 13:45:59 -07:00
|
|
|
binder_node_unlock(node);
|
|
|
|
last_node = node;
|
|
|
|
spin_lock(&binder_dead_nodes_lock);
|
|
|
|
}
|
2016-10-17 12:33:15 -07:00
|
|
|
spin_unlock(&binder_dead_nodes_lock);
|
2017-06-08 13:45:59 -07:00
|
|
|
if (last_node)
|
|
|
|
binder_put_node(last_node);
|
2016-09-30 16:40:04 +02:00
|
|
|
|
2016-10-17 12:33:15 -07:00
|
|
|
mutex_lock(&binder_procs_lock);
|
2017-03-24 15:53:53 -07:00
|
|
|
hlist_for_each_entry(proc, &binder_procs, proc_node)
|
|
|
|
print_binder_proc(m, proc, 1);
|
2016-10-17 12:33:15 -07:00
|
|
|
mutex_unlock(&binder_procs_lock);
|
2016-09-30 16:40:04 +02:00
|
|
|
|
2009-04-28 20:57:50 -07:00
|
|
|
return 0;
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
|
|
|
|
2009-04-28 20:57:50 -07:00
|
|
|
static int binder_stats_show(struct seq_file *m, void *unused)
|
2011-11-30 20:18:14 +09:00
|
|
|
{
|
|
|
|
struct binder_proc *proc;
|
|
|
|
|
2009-04-28 20:57:50 -07:00
|
|
|
seq_puts(m, "binder stats:\n");
|
2011-11-30 20:18:14 +09:00
|
|
|
|
2017-03-24 15:53:53 -07:00
|
|
|
print_binder_stats(m, "", &binder_stats);
|
2011-11-30 20:18:14 +09:00
|
|
|
|
2016-10-17 12:33:15 -07:00
|
|
|
mutex_lock(&binder_procs_lock);
|
2017-03-24 15:53:53 -07:00
|
|
|
hlist_for_each_entry(proc, &binder_procs, proc_node)
|
|
|
|
print_binder_proc_stats(m, proc);
|
2016-10-17 12:33:15 -07:00
|
|
|
mutex_unlock(&binder_procs_lock);
|
2011-11-30 20:18:14 +09:00
|
|
|
|
2009-04-28 20:57:50 -07:00
|
|
|
return 0;
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
|
|
|
|
2009-04-28 20:57:50 -07:00
|
|
|
static int binder_transactions_show(struct seq_file *m, void *unused)
|
2011-11-30 20:18:14 +09:00
|
|
|
{
|
|
|
|
struct binder_proc *proc;
|
|
|
|
|
2009-04-28 20:57:50 -07:00
|
|
|
seq_puts(m, "binder transactions:\n");
|
2016-10-17 12:33:15 -07:00
|
|
|
mutex_lock(&binder_procs_lock);
|
2017-03-24 15:53:53 -07:00
|
|
|
hlist_for_each_entry(proc, &binder_procs, proc_node)
|
|
|
|
print_binder_proc(m, proc, 0);
|
2016-10-17 12:33:15 -07:00
|
|
|
mutex_unlock(&binder_procs_lock);
|
2016-11-14 11:37:41 -08:00
|
|
|
|
2009-04-28 20:57:50 -07:00
|
|
|
return 0;
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
|
|
|
|
2009-04-28 20:57:50 -07:00
|
|
|
static int binder_proc_show(struct seq_file *m, void *unused)
|
2011-11-30 20:18:14 +09:00
|
|
|
{
|
2015-11-09 13:16:32 -08:00
|
|
|
struct binder_proc *itr;
|
2016-10-17 15:17:31 +02:00
|
|
|
int pid = (unsigned long)m->private;
|
2011-11-30 20:18:14 +09:00
|
|
|
|
2016-10-17 12:33:15 -07:00
|
|
|
mutex_lock(&binder_procs_lock);
|
2017-03-24 15:53:53 -07:00
|
|
|
hlist_for_each_entry(itr, &binder_procs, proc_node) {
|
|
|
|
if (itr->pid == pid) {
|
|
|
|
seq_puts(m, "binder proc state:\n");
|
|
|
|
print_binder_proc(m, itr, 1);
|
2015-11-09 13:16:32 -08:00
|
|
|
}
|
|
|
|
}
|
2016-10-17 12:33:15 -07:00
|
|
|
mutex_unlock(&binder_procs_lock);
|
|
|
|
|
2009-04-28 20:57:50 -07:00
|
|
|
return 0;
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
|
|
|
|
2009-04-28 20:57:50 -07:00
|
|
|
static void print_binder_transaction_log_entry(struct seq_file *m,
|
2011-11-30 20:18:14 +09:00
|
|
|
struct binder_transaction_log_entry *e)
|
|
|
|
{
|
2017-05-24 13:33:28 -07:00
|
|
|
int debug_id = READ_ONCE(e->debug_id_done);
|
|
|
|
/*
|
|
|
|
* read barrier to guarantee debug_id_done read before
|
|
|
|
* we print the log values
|
|
|
|
*/
|
|
|
|
smp_rmb();
|
2009-04-28 20:57:50 -07:00
|
|
|
seq_printf(m,
|
2017-05-24 13:33:28 -07:00
|
|
|
"%d: %s from %d:%d to %d:%d context %s node %d handle %d size %d:%d ret %d/%d l=%d",
|
2009-04-28 20:57:50 -07:00
|
|
|
e->debug_id, (e->call_type == 2) ? "reply" :
|
|
|
|
((e->call_type == 1) ? "async" : "call "), e->from_proc,
|
2016-10-17 15:17:31 +02:00
|
|
|
e->from_thread, e->to_proc, e->to_thread, e->context_name,
|
2017-03-22 17:19:52 -07:00
|
|
|
e->to_node, e->target_handle, e->data_size, e->offsets_size,
|
|
|
|
e->return_error, e->return_error_param,
|
|
|
|
e->return_error_line);
|
2017-05-24 13:33:28 -07:00
|
|
|
/*
|
|
|
|
* read-barrier to guarantee read of debug_id_done after
|
|
|
|
* done printing the fields of the entry
|
|
|
|
*/
|
|
|
|
smp_rmb();
|
|
|
|
seq_printf(m, debug_id && debug_id == READ_ONCE(e->debug_id_done) ?
|
|
|
|
"\n" : " (incomplete)\n");
|
2011-11-30 20:18:14 +09:00
|
|
|
}
|
|
|
|
|
2016-09-30 16:40:04 +02:00
|
|
|
static int binder_transaction_log_show(struct seq_file *m, void *unused)
|
|
|
|
{
|
2017-03-24 15:53:53 -07:00
|
|
|
struct binder_transaction_log *log = m->private;
|
2017-05-24 13:33:28 -07:00
|
|
|
unsigned int log_cur = atomic_read(&log->cur);
|
|
|
|
unsigned int count;
|
|
|
|
unsigned int cur;
|
2011-11-30 20:18:14 +09:00
|
|
|
int i;
|
2016-09-30 16:40:04 +02:00
|
|
|
|
2017-05-24 13:33:28 -07:00
|
|
|
count = log_cur + 1;
|
|
|
|
cur = count < ARRAY_SIZE(log->entry) && !log->full ?
|
|
|
|
0 : count % ARRAY_SIZE(log->entry);
|
|
|
|
if (count > ARRAY_SIZE(log->entry) || log->full)
|
|
|
|
count = ARRAY_SIZE(log->entry);
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
unsigned int index = cur++ % ARRAY_SIZE(log->entry);
|
2016-09-30 16:40:04 +02:00
|
|
|
|
2017-05-24 13:33:28 -07:00
|
|
|
print_binder_transaction_log_entry(m, &log->entry[index]);
|
2016-09-30 16:40:04 +02:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-11-30 20:18:14 +09:00
|
|
|
static const struct file_operations binder_fops = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.poll = binder_poll,
|
|
|
|
.unlocked_ioctl = binder_ioctl,
|
2014-02-21 14:40:26 -08:00
|
|
|
.compat_ioctl = binder_ioctl,
|
2011-11-30 20:18:14 +09:00
|
|
|
.mmap = binder_mmap,
|
|
|
|
.open = binder_open,
|
|
|
|
.flush = binder_flush,
|
|
|
|
.release = binder_release,
|
|
|
|
};
|
|
|
|
|
2009-04-28 20:57:50 -07:00
|
|
|
BINDER_DEBUG_ENTRY(state);
|
|
|
|
BINDER_DEBUG_ENTRY(stats);
|
|
|
|
BINDER_DEBUG_ENTRY(transactions);
|
|
|
|
BINDER_DEBUG_ENTRY(transaction_log);
|
|
|
|
|
2016-09-30 16:08:09 +02:00
|
|
|
static int __init init_binder_device(const char *name)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct binder_device *binder_device;
|
|
|
|
|
|
|
|
binder_device = kzalloc(sizeof(*binder_device), GFP_KERNEL);
|
|
|
|
if (!binder_device)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
binder_device->miscdev.fops = &binder_fops;
|
|
|
|
binder_device->miscdev.minor = MISC_DYNAMIC_MINOR;
|
|
|
|
binder_device->miscdev.name = name;
|
|
|
|
|
2017-03-24 15:53:53 -07:00
|
|
|
binder_device->context.binder_context_mgr_uid = INVALID_UID;
|
|
|
|
binder_device->context.name = name;
|
2016-10-17 12:33:15 -07:00
|
|
|
mutex_init(&binder_device->context.context_mgr_node_lock);
|
2016-09-30 16:08:09 +02:00
|
|
|
|
|
|
|
ret = misc_register(&binder_device->miscdev);
|
|
|
|
if (ret < 0) {
|
2017-03-24 15:53:53 -07:00
|
|
|
kfree(binder_device);
|
|
|
|
return ret;
|
2016-09-30 16:08:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
hlist_add_head(&binder_device->hlist, &binder_devices);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-11-30 20:18:14 +09:00
|
|
|
static int __init binder_init(void)
|
|
|
|
{
|
2017-03-24 15:53:53 -07:00
|
|
|
int ret;
|
2016-09-30 16:08:09 +02:00
|
|
|
char *device_name, *device_names;
|
|
|
|
struct binder_device *device;
|
|
|
|
struct hlist_node *tmp;
|
2011-11-30 20:18:14 +09:00
|
|
|
|
2017-07-29 13:24:11 -07:00
|
|
|
binder_alloc_shrinker_init();
|
|
|
|
|
2017-05-24 13:33:28 -07:00
|
|
|
atomic_set(&binder_transaction_log.cur, ~0U);
|
|
|
|
atomic_set(&binder_transaction_log_failed.cur, ~0U);
|
2017-03-24 15:53:53 -07:00
|
|
|
binder_deferred_workqueue = create_singlethread_workqueue("binder");
|
|
|
|
if (!binder_deferred_workqueue)
|
2010-04-22 15:53:23 -07:00
|
|
|
return -ENOMEM;
|
|
|
|
|
2009-04-28 20:57:50 -07:00
|
|
|
binder_debugfs_dir_entry_root = debugfs_create_dir("binder", NULL);
|
|
|
|
if (binder_debugfs_dir_entry_root)
|
|
|
|
binder_debugfs_dir_entry_proc = debugfs_create_dir("proc",
|
|
|
|
binder_debugfs_dir_entry_root);
|
2016-09-30 16:08:09 +02:00
|
|
|
|
2009-04-28 20:57:50 -07:00
|
|
|
if (binder_debugfs_dir_entry_root) {
|
|
|
|
debugfs_create_file("state",
|
|
|
|
S_IRUGO,
|
|
|
|
binder_debugfs_dir_entry_root,
|
|
|
|
NULL,
|
|
|
|
&binder_state_fops);
|
|
|
|
debugfs_create_file("stats",
|
|
|
|
S_IRUGO,
|
|
|
|
binder_debugfs_dir_entry_root,
|
|
|
|
NULL,
|
|
|
|
&binder_stats_fops);
|
|
|
|
debugfs_create_file("transactions",
|
|
|
|
S_IRUGO,
|
|
|
|
binder_debugfs_dir_entry_root,
|
|
|
|
NULL,
|
|
|
|
&binder_transactions_fops);
|
|
|
|
debugfs_create_file("transaction_log",
|
|
|
|
S_IRUGO,
|
|
|
|
binder_debugfs_dir_entry_root,
|
2017-03-24 15:53:53 -07:00
|
|
|
&binder_transaction_log,
|
2009-04-28 20:57:50 -07:00
|
|
|
&binder_transaction_log_fops);
|
|
|
|
debugfs_create_file("failed_transaction_log",
|
|
|
|
S_IRUGO,
|
|
|
|
binder_debugfs_dir_entry_root,
|
2017-03-24 15:53:53 -07:00
|
|
|
&binder_transaction_log_failed,
|
|
|
|
&binder_transaction_log_fops);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copy the module_parameter string, because we don't want to
|
|
|
|
* tokenize it in-place.
|
|
|
|
*/
|
|
|
|
device_names = kzalloc(strlen(binder_devices_param) + 1, GFP_KERNEL);
|
|
|
|
if (!device_names) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto err_alloc_device_names_failed;
|
|
|
|
}
|
|
|
|
strcpy(device_names, binder_devices_param);
|
|
|
|
|
|
|
|
while ((device_name = strsep(&device_names, ","))) {
|
|
|
|
ret = init_binder_device(device_name);
|
|
|
|
if (ret)
|
|
|
|
goto err_init_binder_device_failed;
|
2016-09-30 16:08:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
err_init_binder_device_failed:
|
|
|
|
hlist_for_each_entry_safe(device, tmp, &binder_devices, hlist) {
|
|
|
|
misc_deregister(&device->miscdev);
|
|
|
|
hlist_del(&device->hlist);
|
2017-03-24 15:53:53 -07:00
|
|
|
kfree(device);
|
2016-09-30 16:08:09 +02:00
|
|
|
}
|
2017-03-24 15:53:53 -07:00
|
|
|
err_alloc_device_names_failed:
|
|
|
|
debugfs_remove_recursive(binder_debugfs_dir_entry_root);
|
|
|
|
|
|
|
|
destroy_workqueue(binder_deferred_workqueue);
|
2016-09-30 16:08:09 +02:00
|
|
|
|
2011-11-30 20:18:14 +09:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
device_initcall(binder_init);
|
|
|
|
|
2012-10-16 15:29:53 -07:00
|
|
|
#define CREATE_TRACE_POINTS
|
|
|
|
#include "binder_trace.h"
|
|
|
|
|
2011-11-30 20:18:14 +09:00
|
|
|
MODULE_LICENSE("GPL v2");
|