binder: use standard functions to allocate fds
Todd Kjos
maintainerPATCH v2 1/1 binder: use standard functions to allocate fds
Binder uses internal fs interfaces to allocate and install fds:
__alloc_fd__fd_install__close_fdget_files_structput_files_struct
These were used to support the passing of fds between processes as part of a transaction. The actual allocation and installation of the fds in the target process was handled by the sending process so the standard functions, alloc_fd() and fd_install() which assume task==current couldn't be used.
This patch refactors this mechanism so that the fds are allocated and installed by the target process allowing the standard functions to be used.
The sender now creates a list of fd fixups that contains the struct *file and the address to fixup with the new fd once it is allocated. This list is processed by the target process when the transaction is dequeued.
A new error case is introduced by this change. If an async transaction with file descriptors cannot allocate new fds in the target (probably due to out of file descriptors), the transaction is discarded with a log message. In the old implementation this would have been detected in the sender context and failed prior to sending.
---
v2: use "%zu" printk format for size_t
drivers/android/Kconfig | 2 +- drivers/android/binder.c | 387 ++++++++++++++++++++------------- drivers/android/binder_trace.h | 36 ++- 3 files changed, 260 insertions(+), 165 deletions(-)
drivers/android/Kconfig +1 -1
@@ -10,7 +10,7 @@ if ANDROID config ANDROID_BINDER_IPC bool "Android Binder IPC Driver" - depends on MMU + depends on MMU && !CPU_CACHE_VIVT default n ---help--- Binder is used in Android for both communication between processes,
drivers/android/binder.c +232 -155
585 lines not on this page · raw message
drivers/android/binder_trace.h +27 -9
@@ -223,22 +223,40 @@ TRACE_EVENT(binder_transaction_ref_to_ref, __entry->dest_ref_debug_id, __entry->dest_ref_desc) ); -TRACE_EVENT (binder_transaction_fd, - TP_PROTO(struct binder_transaction *t, int src_fd, int dest_fd), -TP_ARGS (t, src_fd, dest_fd), +TRACE_EVENT (binder_transaction_fd_send, + TP_PROTO(struct binder_transaction *t, int fd, size_t offset), +TP_ARGS (t, fd, offset),TP_STRUCT__entry ( __field(int, debug_id) - __field(int, src_fd) -__field (int, dest_fd) + __field(int, fd) +__field (size_t, offset) + ), +TP_fast_assign ( + __entry->debug_id = t->debug_id; + __entry->fd = fd; + __entry->offset = offset; + ), +TP_printk ("transaction=%d src_fd=%d offset=%zu" , + __entry->debug_id, __entry->fd, __entry->offset) +); + +TRACE_EVENT (binder_transaction_fd_recv, + TP_PROTO(struct binder_transaction *t, int fd, size_t offset), +TP_ARGS (t, fd, offset), + +TP_STRUCT__entry ( + __field(int, debug_id) + __field(int, fd) +__field (size_t, offset) ),TP_fast_assign ( __entry->debug_id = t->debug_id; - __entry->src_fd = src_fd; - __entry->dest_fd = dest_fd; + __entry->fd = fd; + __entry->offset = offset; ), -TP_printk ("transaction=%d src_fd=%d ==> dest_fd=%d" , - __entry->debug_id, __entry->src_fd, __entry->dest_fd) +TP_printk ("transaction=%d dest_fd=%d offset=%zu" , + __entry->debug_id, __entry->fd, __entry->offset) ); DECLARE_EVENT_CLASS(binder_buffer_class,
Signature · 1 line
2.19.0.rc0.228.g281dcd1b4d0-goog
Greg KH
maintainerQuoted 30 lines · Todd Kjos
Binder uses internal fs interfaces to allocate and install fds:
__alloc_fd__fd_install__close_fdget_files_structput_files_structThese were used to support the passing of fds between processes as part of a transaction. The actual allocation and installation of the fds in the target process was handled by the sending process so the standard functions,
alloc_fd()andfd_install()which assume task==current couldn't be used.This patch refactors this mechanism so that the fds are allocated and installed by the target process allowing the standard functions to be used.
The sender now creates a list of fd fixups that contains the struct *file and the address to fixup with the new fd once it is allocated. This list is processed by the target process when the transaction is dequeued.
A new error case is introduced by this change. If an async transaction with file descriptors cannot allocate new fds in the target (probably due to out of file descriptors), the transaction is discarded with a log message. In the old implementation this would have been detected in the sender context and failed prior to sending.
Quoted 3 lines
Signed-off-by Todd Kjos <[email protected]>---
v2: use "%zu" printk format forsize_t
Is this really v3?