From 710da9d05b2760b824d3b391bbede0575319d4d6 Mon Sep 17 00:00:00 2001 From: Sagar Taunk Date: Sun, 27 Sep 2026 12:56:36 +0000 Subject: [PATCH] rust_binder: add transaction buffer tracepoints Add `binder_transaction_alloc_buf`, `binder_transaction_buffer_release`, and `binder_transaction_failed_buffer_release`, mirroring C Binder's `binder_buffer_class` events of the same names and following android's fork for the function signatures. Link: https://github.com/Rust-for-Linux/linux/issues/1226 Suggested-by: Alice Ryhl Signed-off-by: Sagar Taunk Link: https://patch.msgid.link/20260927125622.676342-2-sagartaunk@proton.me Signed-off-by: Greg Kroah-Hartman --- drivers/android/binder/rust_binder_events.h | 42 +++++++++++++++++++++ drivers/android/binder/trace.rs | 37 ++++++++++++++++++ 2 files changed, 79 insertions(+) diff --git a/drivers/android/binder/rust_binder_events.h b/drivers/android/binder/rust_binder_events.h index 1a446787c8b3..045ab77aa44b 100644 --- a/drivers/android/binder/rust_binder_events.h +++ b/drivers/android/binder/rust_binder_events.h @@ -177,6 +177,48 @@ TRACE_EVENT(binder_return, "unknown") ); + +TRACE_EVENT(binder_transaction_alloc_buf, + TP_PROTO(int debug_id, size_t data_size, size_t offsets_size, size_t extra_buffers_size), + TP_ARGS(debug_id, data_size, offsets_size, extra_buffers_size), + TP_STRUCT__entry( + __field(int, debug_id) + __field(size_t, data_size) + __field(size_t, offsets_size) + __field(size_t, extra_buffers_size) + ), + TP_fast_assign( + __entry->debug_id = debug_id; + __entry->data_size = data_size; + __entry->offsets_size = offsets_size; + __entry->extra_buffers_size = extra_buffers_size; + ), + TP_printk("transaction=%d data_size=%zd offsets_size=%zd extra_buffers_size=%zd", + __entry->debug_id, __entry->data_size, __entry->offsets_size, + __entry->extra_buffers_size) +); + +DECLARE_EVENT_CLASS(binder_buffer_release_class, + TP_PROTO(int debug_id), + TP_ARGS(debug_id), + TP_STRUCT__entry( + __field(int, debug_id) + ), + TP_fast_assign( + __entry->debug_id = debug_id; + ), + TP_printk("transaction=%d", __entry->debug_id) +); + +#define DEFINE_RBINDER_FUNCTION_BUFFER_EVENT(name) \ +DEFINE_EVENT(binder_buffer_release_class, name, \ + TP_PROTO(int debug_id), \ + TP_ARGS(debug_id)) + +DEFINE_RBINDER_FUNCTION_BUFFER_EVENT(binder_transaction_buffer_release); +DEFINE_RBINDER_FUNCTION_BUFFER_EVENT(binder_transaction_failed_buffer_release); +DEFINE_RBINDER_FUNCTION_BUFFER_EVENT(binder_transaction_update_buffer_release); + #endif /* _RUST_BINDER_TRACE_H */ /* This part must be outside protection */ diff --git a/drivers/android/binder/trace.rs b/drivers/android/binder/trace.rs index 06aabb3cc2f1..de2894bcb368 100644 --- a/drivers/android/binder/trace.rs +++ b/drivers/android/binder/trace.rs @@ -24,6 +24,11 @@ unsafe fn binder_transaction_fd_recv(t_debug_id: c_int, fd: c_int, offset: usize); unsafe fn binder_command(cmd: u32); unsafe fn binder_return(ret: u32); + unsafe fn binder_transaction_alloc_buf( + debug_id: c_int,data_size: usize, offset_size: usize, extra_buffers_size: usize); + unsafe fn binder_transaction_buffer_release(debug_id: c_int); + unsafe fn binder_transaction_failed_buffer_release(debug_id: c_int); + unsafe fn binder_transaction_update_buffer_release(debug_id: c_int); } #[inline] @@ -105,3 +110,35 @@ pub(crate) fn trace_return(ret: u32) { // SAFETY: This function is always safe to call. unsafe { binder_return(ret) } } +#[inline] +pub(crate) fn trace_transaction_alloc_buf( + debug_id: usize, + data_size: usize, + offset_size: usize, + extra_buffers_size: usize, +) { + // SAFETY: The `data` pointer is valid. + unsafe { + binder_transaction_alloc_buf( + debug_id as c_int, + data_size, + offset_size, + extra_buffers_size, + ) + } +} +#[inline] +pub(crate) fn trace_transaction_buffer_release(debug_id: usize) { + // SAFETY: This function is always safe to call. + unsafe { binder_transaction_buffer_release(debug_id as c_int) } +} +#[inline] +pub(crate) fn trace_transaction_failed_buffer_release(debug_id: usize) { + // SAFETY: This function is always safe to call. + unsafe { binder_transaction_failed_buffer_release(debug_id as c_int) } +} +#[inline] +pub(crate) fn trace_transaction_update_buffer_release(debug_id: usize) { + // SAFETY: This function is always safe to call. + unsafe { binder_transaction_update_buffer_release(debug_id as c_int) } +}