Skip to content

Commit e504952

Browse files
Darksonngregkh
authored andcommitted
rust_binder: introduce TransactionInfo
[ Upstream commit 5326a18 ] Rust Binder exposes information about transactions that are sent in various ways: printing to the kernel log, tracepoints, files in binderfs, and the upcoming netlink support. Currently all these mechanisms use disparate ways of obtaining the same information, so let's introduce a single Info struct that collects all the required information in a single place, so that all of these different mechanisms can operate in a more uniform way. For now, the new info struct is only used to replace a few things: * The BinderTransactionDataSg struct that is passed as an argument to several methods is removed as the information is moved into the new info struct and passed down that way. * The oneway spam detection fields on Transaction and Allocation can be removed, as the information can be returned to the caller via the mutable info struct instead. But several other uses of the info struct are planned in follow-up patches. Signed-off-by: Alice Ryhl <aliceryhl@google.com> Link: https://patch.msgid.link/20260306-transaction-info-v1-1-fda58fca558b@google.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> [aliceryhl: explicitly impl Zeroable for UserPtr instead of using derive] Signed-off-by: Alice Ryhl <aliceryhl@google.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent be15679 commit e504952

6 files changed

Lines changed: 170 additions & 134 deletions

File tree

drivers/android/binder/allocation.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ pub(crate) struct Allocation {
5656
pub(crate) process: Arc<Process>,
5757
allocation_info: Option<AllocationInfo>,
5858
free_on_drop: bool,
59-
pub(crate) oneway_spam_detected: bool,
6059
#[allow(dead_code)]
6160
pub(crate) debug_id: usize,
6261
}
@@ -68,15 +67,13 @@ impl Allocation {
6867
offset: usize,
6968
size: usize,
7069
ptr: usize,
71-
oneway_spam_detected: bool,
7270
) -> Self {
7371
Self {
7472
process,
7573
offset,
7674
size,
7775
ptr,
7876
debug_id,
79-
oneway_spam_detected,
8077
allocation_info: None,
8178
free_on_drop: true,
8279
}

drivers/android/binder/error.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub(crate) type BinderResult<T = ()> = core::result::Result<T, BinderError>;
1212
/// errno.
1313
pub(crate) struct BinderError {
1414
pub(crate) reply: u32,
15-
source: Option<Error>,
15+
pub(crate) source: Option<Error>,
1616
}
1717

1818
impl BinderError {
@@ -40,14 +40,6 @@ impl BinderError {
4040
pub(crate) fn is_dead(&self) -> bool {
4141
self.reply == BR_DEAD_REPLY
4242
}
43-
44-
pub(crate) fn as_errno(&self) -> kernel::ffi::c_int {
45-
self.source.unwrap_or(EINVAL).to_errno()
46-
}
47-
48-
pub(crate) fn should_pr_warn(&self) -> bool {
49-
self.source.is_some()
50-
}
5143
}
5244

5345
/// Convert an errno into a `BinderError` and store the errno used to construct it. The errno

drivers/android/binder/process.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ use crate::{
4747
range_alloc::{RangeAllocator, ReserveNew, ReserveNewArgs},
4848
stats::BinderStats,
4949
thread::{PushWorkRes, Thread},
50+
transaction::TransactionInfo,
5051
BinderfsProcFile, DArc, DLArc, DTRWrap, DeliverToRead,
5152
};
5253

@@ -981,16 +982,15 @@ impl Process {
981982
self: &Arc<Self>,
982983
debug_id: usize,
983984
size: usize,
984-
is_oneway: bool,
985-
from_pid: i32,
985+
info: &mut TransactionInfo,
986986
) -> BinderResult<NewAllocation> {
987987
use kernel::page::PAGE_SIZE;
988988

989989
let mut reserve_new_args = ReserveNewArgs {
990990
debug_id,
991991
size,
992-
is_oneway,
993-
pid: from_pid,
992+
is_oneway: info.is_oneway(),
993+
pid: info.from_pid,
994994
..ReserveNewArgs::default()
995995
};
996996

@@ -1006,13 +1006,13 @@ impl Process {
10061006
reserve_new_args = alloc_request.make_alloc()?;
10071007
};
10081008

1009+
info.oneway_spam_suspect = new_alloc.oneway_spam_detected;
10091010
let res = Allocation::new(
10101011
self.clone(),
10111012
debug_id,
10121013
new_alloc.offset,
10131014
size,
10141015
addr + new_alloc.offset,
1015-
new_alloc.oneway_spam_detected,
10161016
);
10171017

10181018
// This allocation will be marked as in use until the `Allocation` is used to free it.
@@ -1044,7 +1044,7 @@ impl Process {
10441044
let mapping = inner.mapping.as_mut()?;
10451045
let offset = ptr.checked_sub(mapping.address)?;
10461046
let (size, debug_id, odata) = mapping.alloc.reserve_existing(offset).ok()?;
1047-
let mut alloc = Allocation::new(self.clone(), debug_id, offset, size, ptr, false);
1047+
let mut alloc = Allocation::new(self.clone(), debug_id, offset, size, ptr);
10481048
if let Some(data) = odata {
10491049
alloc.set_info(data);
10501050
}
@@ -1397,8 +1397,7 @@ impl Process {
13971397
.alloc
13981398
.take_for_each(|offset, size, debug_id, odata| {
13991399
let ptr = offset + address;
1400-
let mut alloc =
1401-
Allocation::new(self.clone(), debug_id, offset, size, ptr, false);
1400+
let mut alloc = Allocation::new(self.clone(), debug_id, offset, size, ptr);
14021401
if let Some(data) = odata {
14031402
alloc.set_info(data);
14041403
}

0 commit comments

Comments
 (0)