[PATCH 0/7] rust_binder : Implement dynamic debug logging mask

From: Jahnavi MN via B4 Relay

Date: Fri Jul 03 2026 - 11:32:14 EST


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@xxxxxxxxxx>
---
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@xxxxxxxxxx>