The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH 0/7] rust_binder : Implement dynamic debug logging mask
@ 2026-07-03 15:29 Jahnavi MN via B4 Relay
  2026-07-03 15:29 ` [PATCH 1/7] rust_binder: Add " Jahnavi MN via B4 Relay
                   ` (6 more replies)
  0 siblings, 7 replies; 12+ messages in thread
From: Jahnavi MN via B4 Relay @ 2026-07-03 15:29 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Arve Hjønnevåg, Todd Kjos,
	Christian Brauner, Carlos Llamas, Alice Ryhl, Miguel Ojeda,
	Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
	Andreas Hindborg, Trevor Gross, Danilo Krummrich, Daniel Almeida,
	Tamir Duberstein, Alexandre Courbot, Onur Özkan
  Cc: linux-kernel, rust-for-linux, Jahnavi MN

Why we implemented this feature : 

While working with and testing the Rust implementation of the Binder 
driver (rust_binder), we realized that diagnosing transaction failures 
and protocol errors was extremely difficult. When a user-space application 
sends malformed data or makes a lifecycle mistake, the driver rejects it 
with a generic error code (like `-EINVAL`). Without internal logs, the 
driver acts as a "black box," forcing developers to guess which check 
failed.

In the legacy C Binder driver, this issue is solved using a dynamic 
`debug_mask` module parameter that toggles verbose logs for specific 
subsystems. This series brings the same critical capability to the Rust 
Binder driver to provide developers with clear, real-time feedback.

How this helps and simplifies debugging : 
Instead of rebuilds, reboots, or guessing:
- Developers can enable logs instantly on a running device by writing to 
  `/sys/module/rust_binder/parameters/debug_mask`.
- It prints the exact reason for failures (such as alignment errors, 
  mismatched call stacks, or invalid handle references) directly into 
  `dmesg`, reducing debugging time from hours to seconds.
- It protects system logs by keeping logging off by default and only 
  enabling it when developers are actively troubleshooting.

Code development approach : 
We built this system in a structured, progressive approach:
1. Infrastructure Bridging (C/Rust FFI) :
   Because the Rust `module!` macro cannot yet declare parameters, we 
   declared `debug_mask` in a C companion file and linked to it in Rust via 
   FFI. We used volatile memory reads to ensure changes to the mask are 
   detected instantly at runtime.
   
2. Verification Setup :
   We created a `binder_debug!` macro and instrumented process `open`, 
   `flush`, and `release` calls under the `BINDER_DEBUG_OPEN_CLOSE` mask. 
   These low-frequency events allowed us to verify the setup without log 
   flooding.
   
3. Targeted Instrumentation :
   We then systematically added detailed logs across 3 major categories:
   - User Error : Captures API misuse like misaligned FD arrays, 
     negative reference count transitions, and invalid death/freeze 
     notifications.
   - Failed Transaction : Dumps a complete diagnostics log on 
     transaction errors (IDs, PIDs, sizes, OOM states, and line numbers).
   - Dead Transaction : Logs in-flight cancellations, aborted 
     replies, and notification cleanups when processes exit prematurely.

Signed-off-by: Jahnavi MN <jahnavimn@google.com>
---
Jahnavi MN (7):
      rust_binder: Add dynamic debug logging mask
      rust_binder: Implement the BINDER_DEBUG_USER_ERROR logging mask for freezer-related operation
      rust_binder: Implement the BINDER_DEBUG_USER_ERROR logging mask for reference counting and death notification operations
      rust_binder: Implement the BINDER_DEBUG_USER_ERROR logging mask for transaction parsing and protocol validation failures
      rust_binder: Implement the BINDER_DEBUG_FAILED_TRANSACTION logging mask for transaction parsing and routing failures
      rust_binder: Implement BINDER_DEBUG_FAILED_TRANSACTION logging for death notification allocation failures
      rust_binder: Implement the BINDER_DEBUG_DEAD_TRANSACTION logging mask to trace in-flight cancellations during teardown

 drivers/android/binder/debug.rs            |  49 ++++++++++
 drivers/android/binder/freeze.rs           |  57 ++++++++---
 drivers/android/binder/node.rs             |  24 ++++-
 drivers/android/binder/process.rs          |  71 +++++++++++---
 drivers/android/binder/rust_binder_main.rs |  11 ++-
 drivers/android/binder/rust_binderfs.c     |   3 +
 drivers/android/binder/thread.rs           | 147 +++++++++++++++++++++++++----
 drivers/android/binder/transaction.rs      |  16 +++-
 8 files changed, 328 insertions(+), 50 deletions(-)
---
base-commit: dc59e4fea9d83f03bad6bddf3fa2e52491777482
change-id: 20260702-rust_binder_debug_mask-636737015624

Best regards,
-- 
Jahnavi MN <jahnavimn@google.com>



^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2026-07-04 21:17 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-03 15:29 [PATCH 0/7] rust_binder : Implement dynamic debug logging mask Jahnavi MN via B4 Relay
2026-07-03 15:29 ` [PATCH 1/7] rust_binder: Add " Jahnavi MN via B4 Relay
2026-07-03 16:23   ` Gary Guo
2026-07-04 21:03   ` Alice Ryhl
2026-07-03 15:29 ` [PATCH 2/7] rust_binder: Implement the BINDER_DEBUG_USER_ERROR logging mask for freezer-related operation Jahnavi MN via B4 Relay
2026-07-03 15:29 ` [PATCH 3/7] rust_binder: Implement the BINDER_DEBUG_USER_ERROR logging mask for reference counting and death notification operations Jahnavi MN via B4 Relay
2026-07-04 21:14   ` Alice Ryhl
2026-07-03 15:29 ` [PATCH 4/7] rust_binder: Implement the BINDER_DEBUG_USER_ERROR logging mask for transaction parsing and protocol validation failures Jahnavi MN via B4 Relay
2026-07-03 15:29 ` [PATCH 5/7] rust_binder: Implement the BINDER_DEBUG_FAILED_TRANSACTION logging mask for transaction parsing and routing failures Jahnavi MN via B4 Relay
2026-07-03 15:29 ` [PATCH 6/7] rust_binder: Implement BINDER_DEBUG_FAILED_TRANSACTION logging for death notification allocation failures Jahnavi MN via B4 Relay
2026-07-04 21:17   ` Alice Ryhl
2026-07-03 15:29 ` [PATCH 7/7] rust_binder: Implement the BINDER_DEBUG_DEAD_TRANSACTION logging mask to trace in-flight cancellations during teardown Jahnavi MN via B4 Relay

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox