mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-10-26 10:57:38 +08:00
To avoid DoS from printing too much, make printing in Binder rate limited. A big portion of these print statements have been updated to use binder_debug!, but some still remain to be converted. For now, just update them to use pr_*_ratelimited! until we get around to converting them to use binder_debug! too. While we're at it, fix the missing newlines at the end of some of those println statements. Four transaction failure pr_warn! calls in thread.rs and transaction.rs are not converted because they're being deleted by another patch series. Acked-by: Carlos Llamas <cmllamas@google.com> Signed-off-by: Alice Ryhl <aliceryhl@google.com> Link: https://patch.msgid.link/20261007-pr-ratelimited-v6-4-f14accd4ea3b@google.com Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
77 lines
2.4 KiB
Rust
77 lines
2.4 KiB
Rust
// SPDX-License-Identifier: GPL-2.0
|
|
// Copyright (C) 2026 Google LLC.
|
|
|
|
//! Binder debugging helpers.
|
|
|
|
#![allow(dead_code)]
|
|
|
|
use kernel::bits::bit_u32;
|
|
use kernel::sync::atomic::Atomic;
|
|
|
|
kernel::impl_flags!(
|
|
/// Represents multiple debug mask flags.
|
|
#[derive(Debug, Clone, Default, Copy, PartialEq, Eq)]
|
|
pub struct DebugMasks(u32);
|
|
|
|
/// Represents a single debug mask category.
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
pub enum DebugMask {
|
|
UserError = bit_u32(0),
|
|
FailedTransaction = bit_u32(1),
|
|
DeadTransaction = bit_u32(2),
|
|
OpenClose = bit_u32(3),
|
|
DeadBinder = bit_u32(4),
|
|
DeathNotification = bit_u32(5),
|
|
ReadWrite = bit_u32(6),
|
|
UserRefs = bit_u32(7),
|
|
Threads = bit_u32(8),
|
|
Transaction = bit_u32(9),
|
|
TransactionComplete = bit_u32(10),
|
|
FreeBuffer = bit_u32(11),
|
|
InternalRefs = bit_u32(12),
|
|
PriorityCap = bit_u32(13),
|
|
Spinlocks = bit_u32(14),
|
|
}
|
|
);
|
|
|
|
#[no_mangle]
|
|
pub(crate) static rust_binder_debug_mask: Atomic<u32> = Atomic::new(
|
|
(DebugMask::UserError as u32)
|
|
| (DebugMask::FailedTransaction as u32)
|
|
| (DebugMask::DeadTransaction as u32),
|
|
);
|
|
|
|
/// Checks if the given debug logging category is enabled in the mask.
|
|
pub(crate) fn debug_mask_enabled(mask: DebugMask) -> bool {
|
|
let current_mask = rust_binder_debug_mask.load(kernel::sync::atomic::Relaxed);
|
|
DebugMasks(current_mask).contains(mask)
|
|
}
|
|
|
|
/// Prints a debug log if the specified mask category is enabled.
|
|
#[macro_export]
|
|
macro_rules! binder_debug {
|
|
// Rule to explicitly specify a PID (used in kworkers).
|
|
(pid=$pid:expr, $mask:ident, $($arg:tt)*) => {
|
|
if $crate::debug::debug_mask_enabled($crate::debug::DebugMask::$mask) {
|
|
kernel::pr_info_ratelimited!(
|
|
"{}: {}\n",
|
|
$pid,
|
|
kernel::prelude::fmt!($($arg)*)
|
|
);
|
|
}
|
|
};
|
|
|
|
// Default rule (automatically prepends "PID:TID" of the current calling thread).
|
|
($mask:ident, $($arg:tt)*) => {
|
|
if $crate::debug::debug_mask_enabled($crate::debug::DebugMask::$mask) {
|
|
let thread = kernel::current!();
|
|
kernel::pr_info_ratelimited!(
|
|
"{}:{} {}\n",
|
|
thread.tgid(),
|
|
thread.pid(),
|
|
kernel::prelude::fmt!($($arg)*)
|
|
);
|
|
}
|
|
};
|
|
}
|