]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
rust_binder: add fd translation tracepoints
authorMohamad Alsadhan <mo@sdhn.cc>
Tue, 17 Mar 2026 14:49:46 +0000 (17:49 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 1 Apr 2026 10:18:22 +0000 (12:18 +0200)
Add Rust Binder tracepoint declarations for both `transaction_fd_send`
and `transaction_fd_recv`. Also, wire in the corresponding trace calls
where fd objects are serialised/deserialised.

Signed-off-by: Mohamad Alsadhan <mo@sdhn.cc>
Link: https://patch.msgid.link/20260317-rust-binder-trace-v3-5-6fae4fbcf637@sdhn.cc
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/android/binder/allocation.rs
drivers/android/binder/rust_binder.h
drivers/android/binder/rust_binder_events.h
drivers/android/binder/thread.rs
drivers/android/binder/trace.rs

index 0dc4f364d86d39096d07f19654b4e9238ca2248a..0cab959e4b7e099589c2de2a89a7a0f4537a7410 100644 (file)
@@ -205,6 +205,7 @@ impl Allocation {
             let res = FileDescriptorReservation::get_unused_fd_flags(bindings::O_CLOEXEC)?;
             let fd = res.reserved_fd();
             self.write::<u32>(file_info.buffer_offset, &fd)?;
+            crate::trace::trace_transaction_fd_recv(self.debug_id, fd, file_info.buffer_offset);
 
             reservations.push(
                 Reservation {
index d2284726c025190415239acfa07728caa814d260..3936b9d0b8cd0417ccf4543055a082d277824378 100644 (file)
@@ -99,4 +99,9 @@ static inline size_t rust_binder_node_debug_id(rust_binder_node t)
        return *(size_t *) (t + RUST_BINDER_LAYOUT.n.debug_id);
 }
 
+static inline binder_uintptr_t rust_binder_node_ptr(rust_binder_node t)
+{
+       return *(binder_uintptr_t *) (t + RUST_BINDER_LAYOUT.n.ptr);
+}
+
 #endif
index 8a0b72bf025500901c4540f4ed00f2ce7cfc2032..572a4bf7d1d0b6e1496022e4e06baef4399ec0c5 100644 (file)
@@ -111,6 +111,40 @@ TRACE_EVENT(binder_transaction_received,
        TP_printk("transaction=%d", __entry->debug_id)
 );
 
+TRACE_EVENT(binder_transaction_fd_send,
+       TP_PROTO(int t_debug_id, int fd, size_t offset),
+       TP_ARGS(t_debug_id, 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->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(int t_debug_id, int fd, size_t offset),
+       TP_ARGS(t_debug_id, 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->fd = fd;
+               __entry->offset = offset;
+       ),
+       TP_printk("transaction=%d dest_fd=%d offset=%zu",
+                 __entry->debug_id, __entry->fd, __entry->offset)
+);
+
 #endif /* _RUST_BINDER_TRACE_H */
 
 /* This part must be outside protection */
index 62e293e1a4b8ba696d797aa5e3a91dd4f83d43fa..1feac87026e69d231183054ef240d6920a88a4bd 100644 (file)
@@ -712,6 +712,7 @@ impl Thread {
                     core::mem::offset_of!(uapi::binder_fd_object, __bindgen_anon_1.fd);
 
                 let field_offset = offset + FD_FIELD_OFFSET;
+                crate::trace::trace_transaction_fd_send(view.alloc.debug_id, fd, field_offset);
 
                 view.alloc.info_add_fd(file, field_offset, false)?;
             }
index d96afdb79c658cf3d84b458910ca4651c8d6de56..c6f39d83314e66fcf8146bdd8a1a037cdab84b7f 100644 (file)
@@ -18,6 +18,8 @@ declare_trace! {
     unsafe fn binder_wait_for_work(proc_work: bool, transaction_stack: bool, thread_todo: bool);
     unsafe fn binder_transaction(reply: bool, t: rust_binder_transaction, thread: *mut task_struct);
     unsafe fn binder_transaction_received(t: rust_binder_transaction);
+    unsafe fn binder_transaction_fd_send(t_debug_id: c_int, fd: c_int, offset: usize);
+    unsafe fn binder_transaction_fd_recv(t_debug_id: c_int, fd: c_int, offset: usize);
 }
 
 #[inline]
@@ -77,3 +79,14 @@ pub(crate) fn trace_transaction_received(t: &Transaction) {
     // SAFETY: The raw transaction is valid for the duration of this call.
     unsafe { binder_transaction_received(raw_transaction(t)) }
 }
+
+#[inline]
+pub(crate) fn trace_transaction_fd_send(t_debug_id: usize, fd: u32, offset: usize) {
+    // SAFETY: This function is always safe to call.
+    unsafe { binder_transaction_fd_send(t_debug_id as c_int, fd as c_int, offset) }
+}
+#[inline]
+pub(crate) fn trace_transaction_fd_recv(t_debug_id: usize, fd: u32, offset: usize) {
+    // SAFETY: This function is always safe to call.
+    unsafe { binder_transaction_fd_recv(t_debug_id as c_int, fd as c_int, offset) }
+}