From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7A982502D57 for ; Wed, 30 Sep 2026 13:56:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.70 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790776639; cv=none; b=jfXz0J4Fb5/Em2BOAydjFLUAZJph8Mbvxx4Tjqmu6iCtrFvRCH4irTqFM9NvePYND5jLc4ehrjE9rGLCluF9Hpp4PNXKXZzPZ84aX5uxKFVXGF/NLJjhtTw5QliSc6k/kmOKaioBfbHaf64eO/bLqmd36lfp6a+bZ1hDrXg08Fw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790776639; c=relaxed/simple; bh=vGGDVjLC09s48U3k1qX7gwjaijwncQ7MReLddgaTPd4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Y1Y8Ib4zTCxkDfckTPhw9QhRS/2xjp7rqYXmjAyLicFVS9oJ+/IIn85l2lFjmZ1SzW1kpalmhrGbQhOs1SAuF+O3iVdNE1qJzLFr8d7L2A8dsYY9ng7twnk3h18QeIe5B8EBVl5rWp4ms3lsTEvDBvitjY9a86dgS5w13GhBXsA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=kY1sI+uY; arc=none smtp.client-ip=209.85.128.70 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="kY1sI+uY" Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-4a01b112fa2so5442535e9.1 for ; Wed, 30 Sep 2026 06:56:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1790776610; x=1791381410; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=blqXgq5EGfKzLgsqXCTXwzj804Jg40uRL0YfTN/510s=; b=kY1sI+uYXlf+LsrfXm4i0++nvIGbM9xZWuDt3hB+5B/Hnc1QlCUzn0NjJg21IzKgoN vn8FO0dS9VkhdIM4poqW03PCzn0Ba4Nep0V1MGCpGTm6Hg5IFcvK84j6mTnezUsMzZvL BsqXSe4viFd7Xj22RHJaCbXY2aCAmZPN8FUTth+Q6RpBC5vdX4GnX5s2fFxKATXFeXdj XKR9EZ2GcOclDan3lp383DrA+4tm7LEOyFj6nmVOp/u1o0i14E311XR/DFBkbs7GVL/I cpTs+88ZV0Qhh8uYSugTEWXwyQJD0BVF9Gnd+O6HSebL64xar8MacpxwUf9wDFp++BG7 cRqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790776610; x=1791381410; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=blqXgq5EGfKzLgsqXCTXwzj804Jg40uRL0YfTN/510s=; b=Vg4sGQlHRFJvQeZokc/nab/OPYOFlqIsIcCJvc3Z+GWnT5CG91qBdDPFUx7QCKCjWT OBONbwfBoJPR9BfVQGpFPg2nuZFivo6e4u3bQ+xp60I3UxVXiljZ1svmlEQRlHLCmJyH gFSoNokP2lq+AR+lLZu6Uz9bZY7wec6ft8E7dPYY98tVWTk6CpATOgh1F9iJKcR0/Ms1 X2aGIzSFIJF1Nohs6YEnSm1cNTgL+H1si1hpefb7KwPQgjqQVeaY+9b4J48Lon5oNHJx Y1vCwgBc1CEpKsEoVdL4PU+Lp5VAXmFEEvSApG28SZc+vkgOgjYP9CKBym3xJ8edMNL1 B35A== X-Forwarded-Encrypted: i=1; AKwUvBz36EzdxfsTOOP9xPYuoJl2hx7TzTObolydliJP3sn4XVJdNsQGC/pjn9X/nd4lrLWT21CYAzyGygFvQO4=@vger.kernel.org X-Gm-Message-State: AFuF++lGjzNFPYE0n96uf1NKfYOu4ol2HO64IJlDFS6233uapZS2DwZH 26ckCDPVXxKrkeGZjvqhYvVq+SjtNqG9IidpOMykpr1bvQjZlFFnEDzJsuEU57TQJd4NkIeYTvM kZMjodwviicR9bm1OAQ== X-Received: from wmnj10.prod.google.com ([2002:a05:600c:74a:b0:4a0:1976:e6a3]) (user=aliceryhl job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:1d0d:b0:4a0:151e:f743 with SMTP id 5b1f17b1804b1-4a01b00fba0mr25725735e9.19.1790776609241; Wed, 30 Sep 2026 06:56:49 -0700 (PDT) Date: Wed, 30 Sep 2026 13:56:37 +0000 In-Reply-To: <20260930-binder-transaction-log-v2-0-8a15e9b8cae3@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260930-binder-transaction-log-v2-0-8a15e9b8cae3@google.com> X-Developer-Key: i=aliceryhl@google.com; a=openpgp; fpr=49F6C1FAA74960F43A5B86A1EE7A392FDE96209F X-Developer-Signature: v=1; a=openpgp-sha256; l=7267; i=aliceryhl@google.com; h=from:subject:message-id; bh=vGGDVjLC09s48U3k1qX7gwjaijwncQ7MReLddgaTPd4=; b=owEBbQKS/ZANAwAKAQRYvu5YxjlGAcsmYgBqvRUcYwEGEjMf0u5ICpPCcCoWqheqDpnkhmTf9 YhOHi8PH5qJAjMEAAEKAB0WIQSDkqKUTWQHCvFIvbIEWL7uWMY5RgUCar0VHAAKCRAEWL7uWMY5 RjQHEACjwmQkewzjA6iWfgtCUl0f1+B0CUau3wHPSMBmxLlps+yREf/t1JfIYVwTQIDuEypk2g6 w1j3D+PilKhZHPBpugWgIPmbL39k9GbaiVaE57zMaP9vGKLgC3lriU7lQYE5IR8v+BkMAIAjj2X n6nREsZWo/epDpOdPyjXkiVg8W4u+0LQNSKV1qS/uIfRSbrVmlSpBgECxb2g+yDdA86irCvJY7w L1DRu90phsv1qVBcQih/Ew9seV+g9uIMLxg1DChTtGfBI8Pj7dFUo+8XqezOJvWgycX6xkulGMp M2aKlZ+owxTqXRGD7HYRGwlA4QzmNLwDivDV0yDIQYnaDNAWUQ/l9qZhPq584l9UmDn1HHI7mTc Bi7T6UmBuwXDQ20TGc7kJ1W1/aPpmiJfZCm3Sl6OgF3tMJ2byrd0/JNQ4myVp2qbQwQtjAW5qZk B4xn0KwcAx3OMOVZx1FaB5qOYMleOdTFw9mL5pcpfiUeGbg4W3aLXFrvP3+5D6MsJW1nl9aZsge dJO3AOt006Gc/oQ2583jp3W50wzCPItihRx0M8N39xLaHq4yN5ObcCcG4AL0kKkYsGhsxt6VK7w pg9DIcq/hg5AwsDm5wxM6t1yasvNSKoZa3yp0V3r1RSKivxPnbtAEdBf59zbfMOpo3y9FvQXz+g Yww7R59hW8XIOlw== X-Mailer: b4 0.14.3 Message-ID: <20260930-binder-transaction-log-v2-2-8a15e9b8cae3@google.com> Subject: [PATCH v2 2/3] rust_binder: track caller location in BinderError From: Alice Ryhl To: Greg Kroah-Hartman , Carlos Llamas Cc: Miguel Ojeda , Boqun Feng , Gary Guo , "=?utf-8?q?Bj=C3=B6rn_Roy_Baron?=" , Benno Lossin , Andreas Hindborg , Trevor Gross , Danilo Krummrich , Daniel Almeida , Tamir Duberstein , Alexandre Courbot , "=?utf-8?q?Onur_=C3=96zkan?=" , linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, Alice Ryhl Content-Type: text/plain; charset="utf-8" Record the caller's location in BinderError using #[track_caller] and a new ErrorLocation wrapper around &'static Location<'static> across all BinderError constructors and From implementations. ErrorLocation implements Display by stripping the directory prefix so locations are formatted as filename.rs:line (e.g. process.rs:422). In Context::get_manager_node and Process::buffer_alloc, avoid passing BinderError::new_dead() or BinderError::from() as function pointers to Option::ok_or_else() and Result::map_err() so that #[track_caller] captures the call site in rust_binder correctly. Include the error location in the FailedTransaction debug print and prepare for recording it in the binder transaction log. Example output: rust_binder: 840:4583 transaction async to 7656:0 failed ESRCH, code 1 size 428-16 line thread.rs:711 Assisted-by: LLM Signed-off-by: Alice Ryhl --- drivers/android/binder/context.rs | 8 ++++---- drivers/android/binder/error.rs | 39 +++++++++++++++++++++++++++++++++++++++ drivers/android/binder/process.rs | 5 ++++- drivers/android/binder/thread.rs | 5 +++-- 4 files changed, 50 insertions(+), 7 deletions(-) diff --git a/drivers/android/binder/context.rs b/drivers/android/binder/context.rs index ddddb66b3557..bcc97ddaacd7 100644 --- a/drivers/android/binder/context.rs +++ b/drivers/android/binder/context.rs @@ -134,13 +134,13 @@ pub(crate) fn unset_manager_node(&self) { } pub(crate) fn get_manager_node(&self, strong: bool) -> Result { - self.manager + Ok(self + .manager .lock() .node .as_ref() - .ok_or_else(BinderError::new_dead)? - .clone(strong) - .map_err(BinderError::from) + .ok_or_else(|| BinderError::new_dead())? + .clone(strong)?) } pub(crate) fn for_each_proc(&self, mut func: F) diff --git a/drivers/android/binder/error.rs b/drivers/android/binder/error.rs index 1296072c35d9..41b07d687b30 100644 --- a/drivers/android/binder/error.rs +++ b/drivers/android/binder/error.rs @@ -2,6 +2,7 @@ // Copyright (C) 2025 Google LLC. +use core::panic::Location; use kernel::fmt; use kernel::prelude::*; @@ -9,32 +10,65 @@ pub(crate) type BinderResult = core::result::Result; +/// Wraps a `&'static Location` to format it as `filename.rs:line` without the directory prefix. +#[derive(Copy, Clone)] +#[repr(transparent)] +pub(crate) struct ErrorLocation(&'static Location<'static>); + +// SAFETY: `ErrorLocation` is `repr(transparent)` over a shared reference, which is part of the +// option layout optimization guarantee, so all zeroes is a valid representation for `None`. +unsafe impl pin_init::ZeroableOption for ErrorLocation {} + +impl ErrorLocation { + #[track_caller] + pub(crate) const fn caller() -> Self { + Self(Location::caller()) + } +} + +impl fmt::Display for ErrorLocation { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let file = match self.0.file().rsplit_once('/') { + Some((_, file)) => file, + None => self.0.file(), + }; + write!(f, "{}:{}", file, self.0.line()) + } +} + /// An error that will be returned to userspace via the `BINDER_WRITE_READ` ioctl rather than via /// errno. pub(crate) struct BinderError { pub(crate) reply: u32, pub(crate) source: Option, + pub(crate) line: ErrorLocation, } impl BinderError { + #[track_caller] pub(crate) fn new_dead() -> Self { Self { reply: BR_DEAD_REPLY, source: None, + line: ErrorLocation::caller(), } } + #[track_caller] pub(crate) fn new_frozen() -> Self { Self { reply: BR_FROZEN_REPLY, source: None, + line: ErrorLocation::caller(), } } + #[track_caller] pub(crate) fn new_frozen_oneway() -> Self { Self { reply: BR_TRANSACTION_PENDING_FROZEN, source: None, + line: ErrorLocation::caller(), } } @@ -46,25 +80,30 @@ pub(crate) fn is_dead(&self) -> bool { /// Convert an errno into a `BinderError` and store the errno used to construct it. The errno /// should be stored as the thread's extended error when given to userspace. impl From for BinderError { + #[track_caller] fn from(source: Error) -> Self { Self { reply: BR_FAILED_REPLY, source: Some(source), + line: ErrorLocation::caller(), } } } impl From for BinderError { + #[track_caller] fn from(source: kernel::fs::file::BadFdError) -> Self { BinderError::from(Error::from(source)) } } impl From for BinderError { + #[track_caller] fn from(_: kernel::alloc::AllocError) -> Self { Self { reply: BR_FAILED_REPLY, source: Some(ENOMEM), + line: ErrorLocation::caller(), } } } diff --git a/drivers/android/binder/process.rs b/drivers/android/binder/process.rs index 5372bfbd93b3..dcf6ba4bc71b 100644 --- a/drivers/android/binder/process.rs +++ b/drivers/android/binder/process.rs @@ -1066,7 +1066,10 @@ pub(crate) fn buffer_alloc( let (new_alloc, addr) = loop { let mut inner = self.inner.lock(); - let mapping = inner.mapping.as_mut().ok_or_else(BinderError::new_dead)?; + let mapping = inner + .mapping + .as_mut() + .ok_or_else(|| BinderError::new_dead())?; let alloc_request = match mapping.alloc.reserve_new(reserve_new_args)? { ReserveNew::Success(new_alloc) => break (new_alloc, mapping.address), ReserveNew::NeedAlloc(request) => request, diff --git a/drivers/android/binder/thread.rs b/drivers/android/binder/thread.rs index 18a14aa8a835..0891a36e9cbd 100644 --- a/drivers/android/binder/thread.rs +++ b/drivers/android/binder/thread.rs @@ -1310,7 +1310,7 @@ fn transaction(self: &Arc, cmd: u32, reader: &mut UserSliceReader) -> Resu binder_debug!( FailedTransaction, - "transaction {} to {}:{} failed {:?}, code {} size {}-{}", + "transaction {} to {}:{} failed {:?}, code {} size {}-{} line {}", if info.is_reply { "reply" } else if info.is_oneway() { @@ -1323,7 +1323,8 @@ fn transaction(self: &Arc, cmd: u32, reader: &mut UserSliceReader) -> Resu err, info.code, info.data_size, - info.offsets_size + info.offsets_size, + err.line ); } } -- 2.56.0.rc1.315.gc6ed9934b7-goog