]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
rust_binder: add `command`/`return` tracepoints
authorMohamad Alsadhan <mo@sdhn.cc>
Tue, 17 Mar 2026 14:49:47 +0000 (17:49 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 1 Apr 2026 10:18:22 +0000 (12:18 +0200)
Add Rust Binder `command` and `return` tracepoint declarations and
wire them in where BC commands are parsed and BR return codes are
emitted to userspace.

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

index 572a4bf7d1d0b6e1496022e4e06baef4399ec0c5..1a446787c8b3b4d286c09246560719ecff1ba602 100644 (file)
@@ -145,6 +145,38 @@ TRACE_EVENT(binder_transaction_fd_recv,
                  __entry->debug_id, __entry->fd, __entry->offset)
 );
 
+TRACE_EVENT(binder_command,
+       TP_PROTO(uint32_t cmd),
+       TP_ARGS(cmd),
+       TP_STRUCT__entry(
+               __field(uint32_t, cmd)
+       ),
+       TP_fast_assign(
+               __entry->cmd = cmd;
+       ),
+       TP_printk("cmd=0x%x %s",
+                 __entry->cmd,
+                 _IOC_NR(__entry->cmd) < ARRAY_SIZE(binder_command_strings) ?
+                         binder_command_strings[_IOC_NR(__entry->cmd)] :
+                         "unknown")
+);
+
+TRACE_EVENT(binder_return,
+       TP_PROTO(uint32_t cmd),
+       TP_ARGS(cmd),
+       TP_STRUCT__entry(
+               __field(uint32_t, cmd)
+       ),
+       TP_fast_assign(
+               __entry->cmd = cmd;
+       ),
+       TP_printk("cmd=0x%x %s",
+                 __entry->cmd,
+                 _IOC_NR(__entry->cmd) < ARRAY_SIZE(binder_return_strings) ?
+                         binder_return_strings[_IOC_NR(__entry->cmd)] :
+                         "unknown")
+);
+
 #endif /* _RUST_BINDER_TRACE_H */
 
 /* This part must be outside protection */
index dccb7ba3ffc0f8a314c5c37290d8233417b9271b..bd26b61b219224602d2cd55b5204ed9fc080b29c 100644 (file)
@@ -116,6 +116,7 @@ impl<'a> BinderReturnWriter<'a> {
     /// Write a return code back to user space.
     /// Should be a `BR_` constant from [`defs`] e.g. [`defs::BR_TRANSACTION_COMPLETE`].
     fn write_code(&mut self, code: u32) -> Result {
+        crate::trace::trace_return(code);
         stats::GLOBAL_STATS.inc_br(code);
         self.thread.process.stats.inc_br(code);
         self.writer.write(&code)
index 1feac87026e69d231183054ef240d6920a88a4bd..97d5f31e8fe3c51d6e0a600fdbcc5b5d2d3a70f8 100644 (file)
@@ -1370,6 +1370,7 @@ impl Thread {
         while reader.len() >= size_of::<u32>() && self.inner.lock().return_work.is_unused() {
             let before = reader.len();
             let cmd = reader.read::<u32>()?;
+            crate::trace::trace_command(cmd);
             GLOBAL_STATS.inc_bc(cmd);
             self.process.stats.inc_bc(cmd);
             match cmd {
index c6f39d83314e66fcf8146bdd8a1a037cdab84b7f..5539672d7285ae0b4f437af0612311c73ba54707 100644 (file)
@@ -20,6 +20,8 @@ declare_trace! {
     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);
+    unsafe fn binder_command(cmd: u32);
+    unsafe fn binder_return(ret: u32);
 }
 
 #[inline]
@@ -90,3 +92,14 @@ pub(crate) fn trace_transaction_fd_recv(t_debug_id: usize, fd: u32, offset: usiz
     // SAFETY: This function is always safe to call.
     unsafe { binder_transaction_fd_recv(t_debug_id as c_int, fd as c_int, offset) }
 }
+
+#[inline]
+pub(crate) fn trace_command(cmd: u32) {
+    // SAFETY: This function is always safe to call.
+    unsafe { binder_command(cmd) }
+}
+#[inline]
+pub(crate) fn trace_return(ret: u32) {
+    // SAFETY: This function is always safe to call.
+    unsafe { binder_return(ret) }
+}