From nobody Mon Oct 6 01:23:45 2025 Received: from mail-qk1-f201.google.com (mail-qk1-f201.google.com [209.85.222.201]) (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 89101221FAE for ; Sun, 27 Jul 2025 18:31:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753641072; cv=none; b=ZGa2fLZ54+XYvd3qj2YPKcDusjnmUH/GbnGPSyU3IqNJ71EWANkWEtBLOJP8rVwv+FOZeED6fTKgRMC5AXFCy08/TTtQWQpcw+qKtz7ToxGSRXN8OblMO1pYCjrxbZjtJ78dOloqwlJLSgU2cM3O+4l1VD4VD6iw+XtwuuT1GOs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753641072; c=relaxed/simple; bh=pgcoFaEO5e2jWlUnn8djk+glagmUEPUIlqDIRVPO+QQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=pUYo+/zkaiOFe+p+eRr1BYfx4+SGCNmUXijtFrIrYcgI6Iw5zy5YUCzByTjVuDjJacgYX+0PtWe/yw66mgQJ7M/nz4guFWvvp8238oTCOHw4uGLbMhqAvOSvPkfBJLJY81XUex8IX0FDrg4lNnST5xro49ma0lx6uciSdj5+myc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--cmllamas.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=M9HsAh0y; arc=none smtp.client-ip=209.85.222.201 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--cmllamas.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="M9HsAh0y" Received: by mail-qk1-f201.google.com with SMTP id af79cd13be357-7e333fae758so895844485a.2 for ; Sun, 27 Jul 2025 11:31:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1753641069; x=1754245869; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=07ZTFzAwI7AoDMGWdPj2CS/hPyS57ZZsGkQWvuCqmTo=; b=M9HsAh0y8QBa/suIRNwStk30y+BGInLXwPlziTkopurh88dwi7M4LvE9nGxvYS7UOx QBEP6IVrVs3Sj6EsUGFe7f59Qs4tXEYlVpnd+AQIsUMlR/fXpWKACSXQ794hM7k17esm yxd1BKp+Twyg+27DkYPjnI2xaatjutvvzd/lbOs8QxI7n+PDVEkE5lZSuehSYek4jJ5b 13tG4PSDCRF2d/u96P+lR18NfD5UkBvB2RcLUOyVTAaTyvmr9lpAy1y2VwJi11VGSYk0 ewwneAzlL8yzbH5AxJam3beQs19Zxeaniin/NumIMTZEURA6NFRJoCZSBiDmJUKjI9f+ ldLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753641069; x=1754245869; h=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; bh=07ZTFzAwI7AoDMGWdPj2CS/hPyS57ZZsGkQWvuCqmTo=; b=hiKz0RpJvNAsDpHU9DOe2NuQZYCb6YHz89c5AdIOD3H9OzHLBe289z9AYUSgtn06Zv NBI63cU4Nte7JuDuHf44+4sAp0EAbBOEXWBSCYaPftCQ1Z/2sGX+YvbvuZWW4POJD0jL DYBDL+2jHqHWjzx3A+tqqj6YJs3o+rbxskJTAJwlZ/STeP24RhFAMV19GmSDs4ywGlJw ux1VoiUikJas9RutMWxmVm0X3bexOWPXN2Tp5obrQv8YBEkE4lw+EIUU5Jz3zizg3Q3p 1W5vPTulNjskmRwpHkvYxBrWrFddyAC+Oqdbk1el/MkKQfxieLOqgpKkbcs1Kz7Tt4ie DeKw== X-Forwarded-Encrypted: i=1; AJvYcCXdONeSbVh5kPlSv/ClPQlfnX96A0gzVEZFAeoKLxdokNDZIgw9jAP+UjWWE3GyD29qptNKD4Qon5Dvtc0=@vger.kernel.org X-Gm-Message-State: AOJu0Yy7KLb2hjL5au/vctSRPZLfTA3VQn9bcRdgQ7HDcYbhpQRsZ6p8 zHAphdgY15GH01MMaBlt/3mBexRvvYnlnqK5HKUTQ7xszWvYMape0V73r+/5Yv9AsfrDEZTyPjm 3NdswYbkbwMCHjw== X-Google-Smtp-Source: AGHT+IHjtGI0qmGHLUxczNbE1Waqr8gyN+H+qjHlOz0C8aMabStKlmQJl8rPJ9I4ADTEdjP00E3/3uglgauauQ== X-Received: from pjqx22.prod.google.com ([2002:a17:90a:b016:b0:31e:a865:8b32]) (user=cmllamas job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:3908:b0:312:1d2d:18df with SMTP id 98e67ed59e1d1-31e77a19c31mr11279560a91.23.1753641055397; Sun, 27 Jul 2025 11:30:55 -0700 (PDT) Date: Sun, 27 Jul 2025 18:29:04 +0000 In-Reply-To: <20250727182932.2499194-1-cmllamas@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250727182932.2499194-1-cmllamas@google.com> X-Mailer: git-send-email 2.50.1.470.g6ba607880d-goog Message-ID: <20250727182932.2499194-2-cmllamas@google.com> Subject: [PATCH v20 1/5] binder: pre-allocate binder_transaction From: Carlos Llamas To: Alice Ryhl , Greg Kroah-Hartman , "=?UTF-8?q?Arve=20Hj=C3=B8nnev=C3=A5g?=" , Todd Kjos , Martijn Coenen , Joel Fernandes , Christian Brauner , Carlos Llamas , Suren Baghdasaryan Cc: Tiffany Yang , John Stultz , Shai Barack , "=?UTF-8?q?Thi=C3=A9baud=20Weksteen?=" , kernel-team@android.com, linux-kernel@vger.kernel.org, Jakub Kicinski Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Move the allocation of 'struct binder_transaction' to the beginning of the binder_transaction() function, along with the initialization of all the members that are known at that time. This minor refactoring helps to consolidate the usage of transaction information at later points. This patch is in preparation for binder's generic netlink implementation and no functional changes are intended. Signed-off-by: Carlos Llamas --- drivers/android/binder.c | 64 +++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 34 deletions(-) diff --git a/drivers/android/binder.c b/drivers/android/binder.c index 262334851aad..6bb1c9076951 100644 --- a/drivers/android/binder.c +++ b/drivers/android/binder.c @@ -3042,6 +3042,30 @@ static void binder_transaction(struct binder_proc *p= roc, binder_set_extended_error(&thread->ee, t_debug_id, BR_OK, 0); binder_inner_proc_unlock(proc); =20 + t =3D kzalloc(sizeof(*t), GFP_KERNEL); + if (!t) { + binder_txn_error("%d:%d cannot allocate transaction\n", + thread->pid, proc->pid); + return_error =3D BR_FAILED_REPLY; + return_error_param =3D -ENOMEM; + return_error_line =3D __LINE__; + goto err_alloc_t_failed; + } + INIT_LIST_HEAD(&t->fd_fixups); + binder_stats_created(BINDER_STAT_TRANSACTION); + spin_lock_init(&t->lock); + t->debug_id =3D t_debug_id; + t->start_time =3D t_start_time; + t->from_pid =3D proc->pid; + t->from_tid =3D thread->pid; + t->sender_euid =3D task_euid(proc->tsk); + t->code =3D tr->code; + t->flags =3D tr->flags; + t->priority =3D task_nice(current); + t->work.type =3D BINDER_WORK_TRANSACTION; + if (!reply && !(tr->flags & TF_ONE_WAY)) + t->from =3D thread; + if (reply) { binder_inner_proc_lock(proc); in_reply_to =3D thread->transaction_stack; @@ -3228,24 +3252,13 @@ static void binder_transaction(struct binder_proc *= proc, } binder_inner_proc_unlock(proc); } + + t->to_proc =3D target_proc; + t->to_thread =3D target_thread; if (target_thread) e->to_thread =3D target_thread->pid; e->to_proc =3D target_proc->pid; =20 - /* TODO: reuse incoming transaction for reply */ - t =3D kzalloc(sizeof(*t), GFP_KERNEL); - if (t =3D=3D NULL) { - binder_txn_error("%d:%d cannot allocate transaction\n", - thread->pid, proc->pid); - return_error =3D BR_FAILED_REPLY; - return_error_param =3D -ENOMEM; - return_error_line =3D __LINE__; - goto err_alloc_t_failed; - } - INIT_LIST_HEAD(&t->fd_fixups); - binder_stats_created(BINDER_STAT_TRANSACTION); - spin_lock_init(&t->lock); - tcomplete =3D kzalloc(sizeof(*tcomplete), GFP_KERNEL); if (tcomplete =3D=3D NULL) { binder_txn_error("%d:%d cannot allocate work for transaction\n", @@ -3257,9 +3270,6 @@ static void binder_transaction(struct binder_proc *pr= oc, } binder_stats_created(BINDER_STAT_TRANSACTION_COMPLETE); =20 - t->debug_id =3D t_debug_id; - t->start_time =3D t_start_time; - if (reply) binder_debug(BINDER_DEBUG_TRANSACTION, "%d:%d BC_REPLY %d -> %d:%d, data size %lld-%lld-%lld\n", @@ -3275,19 +3285,6 @@ static void binder_transaction(struct binder_proc *p= roc, (u64)tr->data_size, (u64)tr->offsets_size, (u64)extra_buffers_size); =20 - if (!reply && !(tr->flags & TF_ONE_WAY)) - t->from =3D thread; - else - t->from =3D NULL; - t->from_pid =3D proc->pid; - t->from_tid =3D thread->pid; - t->sender_euid =3D task_euid(proc->tsk); - t->to_proc =3D target_proc; - t->to_thread =3D target_thread; - t->code =3D tr->code; - t->flags =3D tr->flags; - t->priority =3D task_nice(current); - if (target_node && target_node->txn_security_ctx) { u32 secid; size_t added_size; @@ -3684,7 +3681,6 @@ static void binder_transaction(struct binder_proc *pr= oc, tcomplete->type =3D BINDER_WORK_TRANSACTION_ONEWAY_SPAM_SUSPECT; else tcomplete->type =3D BINDER_WORK_TRANSACTION_COMPLETE; - t->work.type =3D BINDER_WORK_TRANSACTION; =20 if (reply) { binder_enqueue_thread_work(thread, tcomplete); @@ -3783,9 +3779,6 @@ static void binder_transaction(struct binder_proc *pr= oc, err_alloc_tcomplete_failed: if (trace_binder_txn_latency_free_enabled()) binder_txn_latency_free(t); - kfree(t); - binder_stats_deleted(BINDER_STAT_TRANSACTION); -err_alloc_t_failed: err_bad_todo_list: err_bad_call_stack: err_empty_call_stack: @@ -3795,6 +3788,9 @@ static void binder_transaction(struct binder_proc *pr= oc, binder_dec_node(target_node, 1, 0); binder_dec_node_tmpref(target_node); } + kfree(t); + binder_stats_deleted(BINDER_STAT_TRANSACTION); +err_alloc_t_failed: =20 binder_debug(BINDER_DEBUG_FAILED_TRANSACTION, "%d:%d transaction %s to %d:%d failed %d/%d/%d, code %u size %lld-%= lld line %d\n", --=20 2.50.1.470.g6ba607880d-goog From nobody Mon Oct 6 01:23:45 2025 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) (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 38F6D137923 for ; Sun, 27 Jul 2025 18:30:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753641061; cv=none; b=BtGRWelt56rY3uxMdnuhSEAfZCkRpphD/ERFllUwXIHWdvngoQZDS/VqIv3VCG2O/kcrNbF82RDyhn2dZsltn3BNpc+EHPLI6MMEAbpMRNUKaDP8iCuRuULzgxOsp0vd/kIt5e3gJMcGmVSoj36j9g270vC2oj3WkR1olNqd6xc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753641061; c=relaxed/simple; bh=EIkXJlJ7/tVrwsE5890JqYG99zH0rcdBwoFWoNtENeM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Z2VXQSy+r3guDdjG5jjAyTATx371+Pfn/qqIwNorFt4sPrgKNdoakfnDub6ANhps8BLdILRIfkEnUFqkpDtE6CnVwljQTJUoOz8O8fD2Q4ugUMEz+q6FXIXfMnHgvtvXuniGKO+Ompqg+PR5mTYQZEPwGfrIgS5you9jysqQfMg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--cmllamas.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=cp3Autqi; arc=none smtp.client-ip=209.85.214.201 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--cmllamas.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="cp3Autqi" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-23ff063d087so6041475ad.1 for ; Sun, 27 Jul 2025 11:30:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1753641059; x=1754245859; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=WtfOw8me2fehz6S9vL0y0tL4JPXzL4OPlqHFwldn0qA=; b=cp3AutqiOIrLa23pOesWqXvukMMP99aWnet4I0fdMNRVNGipV0fLV79f4YkxGJ5V1i 5jK2U9pIkyyO+aGqtqfLCJPybil+JpZEJbJ7MzYKweuubmuNyOtpQ4ewSCWYVhMMqlQP DtE1fpYI4lYib9Xb3gqtuDnj1wWv527MmktLjCdKEgL0X1K+EtTr1aNwp4AB2hLoRx+d TgLL4NipAS0cEnunlySrM03CZFVSxTIFJltZrtap5gEGcTRr95tvjdhf8CPooR4dKIAz Y4vXwbGgB06dRVXtzW0StIhHxZLWr0rh3i7RmtsqK6rsaiEYqsTX6mODSAOMf7sb0wN4 uWMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753641059; x=1754245859; h=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; bh=WtfOw8me2fehz6S9vL0y0tL4JPXzL4OPlqHFwldn0qA=; b=wJjgITYmIZlt9BwycOQexEZ5pck+WrZEsF32Uq7/UgPuli3jofFUUOjZb8wlKngHXb LUVYj/s1zSYG0+5OPICy5VYZ/3EulaF+l5075yjYAwKkG+VSWEFFj52bcufFjPUfceSc Z8hMJXdU14e+2He8wMOrbeTYf8zb5QPNec6qUTqG/ZKusbECLJBtwdGThwgJDOkfzJWv FnzzFO+HM4hqY27mkeNPuL6AoCfScHdjmP7w9ZtpdBPZtBix9iucPAld8uZZDXv6yURN aKv6CqQObE5X57REqMkOzDkzrMcXiCp2+ZCSzZC4t6uO1vfIOVlde5y4ulkJdy5Jwp8h 960A== X-Forwarded-Encrypted: i=1; AJvYcCWjWSi01RGzv+/gxzuoyMMR7bPs89zcUblIN14eE/5ZpWEp1eWR76Vztve9VOmmOWIGtc0RRlofaezcUuk=@vger.kernel.org X-Gm-Message-State: AOJu0Yzobzg23HJlGn0IH2ir9waE827gQ7gnwcmtFZSx9iDxAhP0QBFB hddjfJ4JxJjcIlNZlTMIWwJj8dneYp9gALI+JtYAKxPKjiI+RQHG+AXao2VIfq69yLTnNAO3pVK CSoiWxAepFDNV5g== X-Google-Smtp-Source: AGHT+IGSkmjG2Ncqd/7AzzGIAL6IFLlDbJiRW2CDnt5lfPA4hkA5BNV7k7rc74a9xl89KBLTsiABl0RMVTOuWw== X-Received: from plgd12.prod.google.com ([2002:a17:902:cecc:b0:240:6ec:28e9]) (user=cmllamas job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:1446:b0:234:d7b2:2ab9 with SMTP id d9443c01a7336-23fb306bcbfmr153785535ad.12.1753641059486; Sun, 27 Jul 2025 11:30:59 -0700 (PDT) Date: Sun, 27 Jul 2025 18:29:05 +0000 In-Reply-To: <20250727182932.2499194-1-cmllamas@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250727182932.2499194-1-cmllamas@google.com> X-Mailer: git-send-email 2.50.1.470.g6ba607880d-goog Message-ID: <20250727182932.2499194-3-cmllamas@google.com> Subject: [PATCH v20 2/5] binder: add t->is_async and t->is_reply From: Carlos Llamas To: Alice Ryhl , Greg Kroah-Hartman , "=?UTF-8?q?Arve=20Hj=C3=B8nnev=C3=A5g?=" , Todd Kjos , Martijn Coenen , Joel Fernandes , Christian Brauner , Carlos Llamas , Suren Baghdasaryan Cc: Tiffany Yang , John Stultz , Shai Barack , "=?UTF-8?q?Thi=C3=A9baud=20Weksteen?=" , kernel-team@android.com, linux-kernel@vger.kernel.org, Jakub Kicinski Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Replace the t->need_reply flag with the more descriptive t->is_async and and t->is_reply flags. The 'need_reply' flag was only used for debugging purposes and the new flags can be used to distinguish between the type of transactions too: sync, async and reply. For now, only update the logging in print_binder_transaction_ilocked(). However, the new flags can be used in the future to replace the current patterns and improve readability. e.g.: - if (!reply && !(tr->flags & TF_ONE_WAY)) + if (t->is_async) This patch is in preparation for binder's generic netlink implementation and no functional changes are intended. Signed-off-by: Carlos Llamas --- drivers/android/binder.c | 7 ++++--- drivers/android/binder_internal.h | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/android/binder.c b/drivers/android/binder.c index 6bb1c9076951..95aa1fae53e2 100644 --- a/drivers/android/binder.c +++ b/drivers/android/binder.c @@ -3063,6 +3063,8 @@ static void binder_transaction(struct binder_proc *pr= oc, t->flags =3D tr->flags; t->priority =3D task_nice(current); t->work.type =3D BINDER_WORK_TRANSACTION; + t->is_async =3D !reply && (tr->flags & TF_ONE_WAY); + t->is_reply =3D reply; if (!reply && !(tr->flags & TF_ONE_WAY)) t->from =3D thread; =20 @@ -3708,7 +3710,6 @@ static void binder_transaction(struct binder_proc *pr= oc, * the target replies (or there is an error). */ binder_enqueue_deferred_thread_work_ilocked(thread, tcomplete); - t->need_reply =3D 1; t->from_parent =3D thread->transaction_stack; thread->transaction_stack =3D t; binder_inner_proc_unlock(proc); @@ -6328,13 +6329,13 @@ static void print_binder_transaction_ilocked(struct= seq_file *m, spin_lock(&t->lock); to_proc =3D t->to_proc; seq_printf(m, - "%s %d: %pK from %d:%d to %d:%d code %x flags %x pri %ld r%d elapsed = %lldms", + "%s %d: %pK from %d:%d to %d:%d code %x flags %x pri %ld a%d r%d elap= sed %lldms", prefix, t->debug_id, t, t->from_pid, t->from_tid, to_proc ? to_proc->pid : 0, t->to_thread ? t->to_thread->pid : 0, - t->code, t->flags, t->priority, t->need_reply, + t->code, t->flags, t->priority, t->is_async, t->is_reply, ktime_ms_delta(current_time, t->start_time)); spin_unlock(&t->lock); =20 diff --git a/drivers/android/binder_internal.h b/drivers/android/binder_int= ernal.h index b5d3014fb4dc..1b69bba2c816 100644 --- a/drivers/android/binder_internal.h +++ b/drivers/android/binder_internal.h @@ -539,8 +539,8 @@ struct binder_transaction { struct binder_proc *to_proc; struct binder_thread *to_thread; struct binder_transaction *to_parent; - unsigned need_reply:1; - /* unsigned is_dead:1; */ /* not used at the moment */ + unsigned is_async:1; + unsigned is_reply:1; =20 struct binder_buffer *buffer; unsigned int code; --=20 2.50.1.470.g6ba607880d-goog From nobody Mon Oct 6 01:23:45 2025 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) (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 77A27225388 for ; Sun, 27 Jul 2025 18:31:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753641079; cv=none; b=BE01FSv9ZJXg5yd6SMd6w0VgzF8pcBz6mKWtBoRuO8StDqFbLmHxS0XBidp2d33jiLg4QecpAQTR2gLI5ZUMQioX0GjFE/vgoZTgC/wqgcAWoyyAlNe1eJIDLobgCJizWgSet/DNkRevYdjebL62VP67OCJmpBSf9yLda6fRcDM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753641079; c=relaxed/simple; bh=VZxXgmTX4xkNdH+Ek2UIA5rZJuOCQSy5Xc3zBhHKzkM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=ZRYVXSfTgX6D87oMiB2u5aigX3NmQorTY5IE6Pkw1p8f1OEMhb5XY0lYbvUoJ7MQeNBNMbz7JFqmQZAXcwKsfAD/oTA5VeQBMc5q8oWsxWiJjQ94N/w9d9k4dYteP1Lo/FD+huFEqqDs1cTpaWCtMd7Wy7hRqqUSg85aV56UoWY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--cmllamas.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=BAGtK/Mk; arc=none smtp.client-ip=209.85.215.201 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--cmllamas.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="BAGtK/Mk" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-b38ec062983so2565228a12.3 for ; Sun, 27 Jul 2025 11:31:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1753641077; x=1754245877; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=1GJxK0KXsLx9H/XDzvQ6sbb6mZedTCYKkjtJ58DsPSc=; b=BAGtK/MkoRoafZ++NHKS9wdnHYpmrdF1st5VAOFpEvzoqmhvJWpK020dL3GLJIRST1 z3s9LgATWWnK0BJb9p+/rTT34S0kMqAv/OFe/UPfpwHHlvzeJ2/tEyPS+ZsQhTaX+daJ DcWmQf5yB8rMS8/gS5+ExnftvwUIpjdnqBNgZG5ZeCFhJC0pJcleQ84fnT/5HWGTiOAP suLjkH4T/+xJh3jcy5uM5ZbAfXuIDalJ7eAKG+2QcWi7R6EkKA+S7BI5tXPjHyJccRBb dYqEAotZAyfytNsmGJIy63IBgxe9ulUzViNNEI9BUVAnsrSQYCWW8uiavxvw94qwXsAn DxtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753641077; x=1754245877; h=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; bh=1GJxK0KXsLx9H/XDzvQ6sbb6mZedTCYKkjtJ58DsPSc=; b=EcEcNXlSQ7wD5/NVdDZHt/2i9a9XSsKxSby5fSTjxQwfQZExNKWp6VorF3ej3zmfZn kITrzTDMIENPYZStTCn0Oq2LRGVL+Ixx0JmscaEyhSSSWO4YBljhJu6hT37jLI7Unw2E 7quhXpyvyOBoRh9SHGgU50qlshfWTYYbK6L9dm41gAg6x3Nu6amronmW14S6Ayh7CRMU Zo209jo8CRD0L0RdoOmwN6GwbQdn9WmgeaAUfWO+LNeH1jqdDb7b/vjR7961xU/PyF5T 8seeTz1coNTuX3G7ioqH3k0VyWmlKM1W8IBLr4QAZ3TUmOfBxCO5y7K60rTctx9/jGZS ULag== X-Forwarded-Encrypted: i=1; AJvYcCX9wDaYHy9cwkgFMmW//qQfgOE2t2l8Yw8UAoHG87Su0qRHeRztVAf6fWZPbGN/Xtg8jsBud1IZsKMrCp0=@vger.kernel.org X-Gm-Message-State: AOJu0YxTbe3WtQEN2zg1oXZxkj8NgWiqCmjPY+AxdC17oV4tccHPPtpR x5RI3aQfeSE3MJHDbACxucSBWucQ2dStkK1px/4BJt0h8b3pUj1buytf09xcAl5VOaPKF+kwg9W rfMlQQd/HuYl+yQ== X-Google-Smtp-Source: AGHT+IGb92eIG/h+HjV21j+xjnGj1Dz/xo0rOm76wrt0DnmWAXxWGKp/3Ww1XR/lmmbBdyLR0dlj5qxTtLLWSQ== X-Received: from pgac5.prod.google.com ([2002:a05:6a02:2945:b0:b39:24fb:bd64]) (user=cmllamas job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:6d86:b0:22c:fc43:c9f3 with SMTP id adf61e73a8af0-23d70150439mr14962401637.21.1753641076638; Sun, 27 Jul 2025 11:31:16 -0700 (PDT) Date: Sun, 27 Jul 2025 18:29:06 +0000 In-Reply-To: <20250727182932.2499194-1-cmllamas@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250727182932.2499194-1-cmllamas@google.com> X-Mailer: git-send-email 2.50.1.470.g6ba607880d-goog Message-ID: <20250727182932.2499194-4-cmllamas@google.com> Subject: [PATCH v20 3/5] binder: introduce transaction reports via netlink From: Carlos Llamas To: Alice Ryhl , Greg Kroah-Hartman , "=?UTF-8?q?Arve=20Hj=C3=B8nnev=C3=A5g?=" , Todd Kjos , Martijn Coenen , Joel Fernandes , Christian Brauner , Carlos Llamas , Suren Baghdasaryan , Donald Hunter , Jakub Kicinski , "David S. Miller" , Eric Dumazet , Paolo Abeni , Simon Horman , Li Li Cc: Tiffany Yang , John Stultz , Shai Barack , "=?UTF-8?q?Thi=C3=A9baud=20Weksteen?=" , kernel-team@android.com, linux-kernel@vger.kernel.org, "open list:NETWORKING [GENERAL]" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Li Li Introduce a generic netlink multicast event to report binder transaction failures to userspace. This allows subscribers to monitor these events and take appropriate actions, such as stopping a misbehaving application that is spamming a service with huge amount of transactions. The multicast event contains full details of the failed transactions, including the sender/target PIDs, payload size and specific error code. This interface is defined using a YAML spec, from which the UAPI and kernel headers and source are auto-generated. Signed-off-by: Li Li Signed-off-by: Carlos Llamas --- Documentation/netlink/specs/binder.yaml | 93 +++++++++++++++++++++ MAINTAINERS | 1 + drivers/android/Kconfig | 1 + drivers/android/Makefile | 2 +- drivers/android/binder.c | 85 ++++++++++++++++++- drivers/android/binder_netlink.c | 31 +++++++ drivers/android/binder_netlink.h | 20 +++++ include/uapi/linux/android/binder_netlink.h | 37 ++++++++ 8 files changed, 265 insertions(+), 5 deletions(-) create mode 100644 Documentation/netlink/specs/binder.yaml create mode 100644 drivers/android/binder_netlink.c create mode 100644 drivers/android/binder_netlink.h create mode 100644 include/uapi/linux/android/binder_netlink.h diff --git a/Documentation/netlink/specs/binder.yaml b/Documentation/netlin= k/specs/binder.yaml new file mode 100644 index 000000000000..140b77a6afee --- /dev/null +++ b/Documentation/netlink/specs/binder.yaml @@ -0,0 +1,93 @@ +# SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Cla= use) +# +# Copyright 2025 Google LLC +# +--- +name: binder +protocol: genetlink +uapi-header: linux/android/binder_netlink.h +doc: Binder interface over generic netlink + +attribute-sets: + - + name: report + doc: | + Attributes included within a transaction failure report. The elements + correspond directly with the specific transaction that failed, along + with the error returned to the sender e.g. BR_DEAD_REPLY. + + attributes: + - + name: error + type: u32 + doc: The enum binder_driver_return_protocol returned to the sender. + - + name: context + type: string + doc: The binder context where the transaction occurred. + - + name: from_pid + type: u32 + doc: The PID of the sender process. + - + name: from_tid + type: u32 + doc: The TID of the sender thread. + - + name: to_pid + type: u32 + doc: | + The PID of the recipient process. This attribute may not be pres= ent + if the target could not be determined. + - + name: to_tid + type: u32 + doc: | + The TID of the recipient thread. This attribute may not be prese= nt + if the target could not be determined. + - + name: is_reply + type: flag + doc: When present, indicates the failed transaction is a reply. + - + name: flags + type: u32 + doc: The bitmask of enum transaction_flags from the transaction. + - + name: code + type: u32 + doc: The application-defined code from the transaction. + - + name: data_size + type: u32 + doc: The transaction payload size in bytes. + +operations: + list: + - + name: report + doc: | + A multicast event sent to userspace subscribers to notify them abo= ut + binder transaction failures. The generated report provides the full + details of the specific transaction that failed. The intention is = for + programs to monitor these events and react to the failures as need= ed. + + attribute-set: report + mcgrp: report + event: + attributes: + - error + - context + - from_pid + - from_tid + - to_pid + - to_tid + - is_reply + - flags + - code + - data_size + +mcast-groups: + list: + - + name: report diff --git a/MAINTAINERS b/MAINTAINERS index f8c8f682edf6..df8f6b31f2f8 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1769,6 +1769,7 @@ M: Suren Baghdasaryan L: linux-kernel@vger.kernel.org S: Supported T: git git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging.git +F: Documentation/netlink/specs/binder.yaml F: drivers/android/ =20 ANDROID GOLDFISH PIC DRIVER diff --git a/drivers/android/Kconfig b/drivers/android/Kconfig index 5b3b8041f827..75af3cf472c8 100644 --- a/drivers/android/Kconfig +++ b/drivers/android/Kconfig @@ -4,6 +4,7 @@ menu "Android" config ANDROID_BINDER_IPC bool "Android Binder IPC Driver" depends on MMU + depends on NET default n help Binder is used in Android for both communication between processes, diff --git a/drivers/android/Makefile b/drivers/android/Makefile index c5d47be0276c..f422f91e026b 100644 --- a/drivers/android/Makefile +++ b/drivers/android/Makefile @@ -2,5 +2,5 @@ ccflags-y +=3D -I$(src) # needed for trace events =20 obj-$(CONFIG_ANDROID_BINDERFS) +=3D binderfs.o -obj-$(CONFIG_ANDROID_BINDER_IPC) +=3D binder.o binder_alloc.o +obj-$(CONFIG_ANDROID_BINDER_IPC) +=3D binder.o binder_alloc.o binder_netli= nk.o obj-$(CONFIG_ANDROID_BINDER_ALLOC_KUNIT_TEST) +=3D tests/ diff --git a/drivers/android/binder.c b/drivers/android/binder.c index 95aa1fae53e2..0d37eca514f9 100644 --- a/drivers/android/binder.c +++ b/drivers/android/binder.c @@ -74,6 +74,7 @@ =20 #include =20 +#include "binder_netlink.h" #include "binder_internal.h" #include "binder_trace.h" =20 @@ -2993,6 +2994,67 @@ static void binder_set_txn_from_error(struct binder_= transaction *t, int id, binder_thread_dec_tmpref(from); } =20 +/** + * binder_netlink_report() - report a transaction failure via netlink + * @proc: the binder proc sending the transaction + * @t: the binder transaction that failed + * @data_size: the user provided data size for the transaction + * @error: enum binder_driver_return_protocol returned to sender + */ +static void binder_netlink_report(struct binder_proc *proc, + struct binder_transaction *t, + u32 data_size, + u32 error) +{ + const char *context =3D proc->context->name; + struct sk_buff *skb; + void *hdr; + + if (!genl_has_listeners(&binder_nl_family, &init_net, + BINDER_NLGRP_REPORT)) + return; + + skb =3D genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_KERNEL); + if (!skb) + return; + + hdr =3D genlmsg_put(skb, 0, 0, &binder_nl_family, 0, BINDER_CMD_REPORT); + if (!hdr) + goto free_skb; + + if (nla_put_u32(skb, BINDER_A_REPORT_ERROR, error) || + nla_put_string(skb, BINDER_A_REPORT_CONTEXT, context) || + nla_put_u32(skb, BINDER_A_REPORT_FROM_PID, t->from_pid) || + nla_put_u32(skb, BINDER_A_REPORT_FROM_TID, t->from_tid)) + goto cancel_skb; + + if (t->to_proc && + nla_put_u32(skb, BINDER_A_REPORT_TO_PID, t->to_proc->pid)) + goto cancel_skb; + + if (t->to_thread && + nla_put_u32(skb, BINDER_A_REPORT_TO_TID, t->to_thread->pid)) + goto cancel_skb; + + if (t->is_reply && nla_put_flag(skb, BINDER_A_REPORT_IS_REPLY)) + goto cancel_skb; + + if (nla_put_u32(skb, BINDER_A_REPORT_FLAGS, t->flags) || + nla_put_u32(skb, BINDER_A_REPORT_CODE, t->code) || + nla_put_u32(skb, BINDER_A_REPORT_DATA_SIZE, data_size)) + goto cancel_skb; + + genlmsg_end(skb, hdr); + genlmsg_multicast(&binder_nl_family, skb, 0, BINDER_NLGRP_REPORT, + GFP_KERNEL); + return; + +cancel_skb: + genlmsg_cancel(skb, hdr); +free_skb: + nlmsg_free(skb); +} + static void binder_transaction(struct binder_proc *proc, struct binder_thread *thread, struct binder_transaction_data *tr, int reply, @@ -3679,10 +3741,13 @@ static void binder_transaction(struct binder_proc *= proc, return_error_line =3D __LINE__; goto err_copy_data_failed; } - if (t->buffer->oneway_spam_suspect) + if (t->buffer->oneway_spam_suspect) { tcomplete->type =3D BINDER_WORK_TRANSACTION_ONEWAY_SPAM_SUSPECT; - else + binder_netlink_report(proc, t, tr->data_size, + BR_ONEWAY_SPAM_SUSPECT); + } else { tcomplete->type =3D BINDER_WORK_TRANSACTION_COMPLETE; + } =20 if (reply) { binder_enqueue_thread_work(thread, tcomplete); @@ -3730,8 +3795,11 @@ static void binder_transaction(struct binder_proc *p= roc, * process and is put in a pending queue, waiting for the target * process to be unfrozen. */ - if (return_error =3D=3D BR_TRANSACTION_PENDING_FROZEN) + if (return_error =3D=3D BR_TRANSACTION_PENDING_FROZEN) { tcomplete->type =3D BINDER_WORK_TRANSACTION_PENDING; + binder_netlink_report(proc, t, tr->data_size, + return_error); + } binder_enqueue_thread_work(thread, tcomplete); if (return_error && return_error !=3D BR_TRANSACTION_PENDING_FROZEN) @@ -3789,6 +3857,8 @@ static void binder_transaction(struct binder_proc *pr= oc, binder_dec_node(target_node, 1, 0); binder_dec_node_tmpref(target_node); } + + binder_netlink_report(proc, t, tr->data_size, return_error); kfree(t); binder_stats_deleted(BINDER_STAT_TRANSACTION); err_alloc_t_failed: @@ -7067,12 +7137,19 @@ static int __init binder_init(void) } } =20 - ret =3D init_binderfs(); + ret =3D genl_register_family(&binder_nl_family); if (ret) goto err_init_binder_device_failed; =20 + ret =3D init_binderfs(); + if (ret) + goto err_init_binderfs_failed; + return ret; =20 +err_init_binderfs_failed: + genl_unregister_family(&binder_nl_family); + err_init_binder_device_failed: hlist_for_each_entry_safe(device, tmp, &binder_devices, hlist) { misc_deregister(&device->miscdev); diff --git a/drivers/android/binder_netlink.c b/drivers/android/binder_netl= ink.c new file mode 100644 index 000000000000..d05397a50ca6 --- /dev/null +++ b/drivers/android/binder_netlink.c @@ -0,0 +1,31 @@ +// SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Cl= ause) +/* Do not edit directly, auto-generated from: */ +/* Documentation/netlink/specs/binder.yaml */ +/* YNL-GEN kernel source */ + +#include +#include + +#include "binder_netlink.h" + +#include + +/* Ops table for binder */ +static const struct genl_split_ops binder_nl_ops[] =3D { +}; + +static const struct genl_multicast_group binder_nl_mcgrps[] =3D { + [BINDER_NLGRP_REPORT] =3D { "report", }, +}; + +struct genl_family binder_nl_family __ro_after_init =3D { + .name =3D BINDER_FAMILY_NAME, + .version =3D BINDER_FAMILY_VERSION, + .netnsok =3D true, + .parallel_ops =3D true, + .module =3D THIS_MODULE, + .split_ops =3D binder_nl_ops, + .n_split_ops =3D ARRAY_SIZE(binder_nl_ops), + .mcgrps =3D binder_nl_mcgrps, + .n_mcgrps =3D ARRAY_SIZE(binder_nl_mcgrps), +}; diff --git a/drivers/android/binder_netlink.h b/drivers/android/binder_netl= ink.h new file mode 100644 index 000000000000..882c7a6b537e --- /dev/null +++ b/drivers/android/binder_netlink.h @@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Cl= ause) */ +/* Do not edit directly, auto-generated from: */ +/* Documentation/netlink/specs/binder.yaml */ +/* YNL-GEN kernel header */ + +#ifndef _LINUX_BINDER_GEN_H +#define _LINUX_BINDER_GEN_H + +#include +#include + +#include + +enum { + BINDER_NLGRP_REPORT, +}; + +extern struct genl_family binder_nl_family; + +#endif /* _LINUX_BINDER_GEN_H */ diff --git a/include/uapi/linux/android/binder_netlink.h b/include/uapi/lin= ux/android/binder_netlink.h new file mode 100644 index 000000000000..b218f96d6668 --- /dev/null +++ b/include/uapi/linux/android/binder_netlink.h @@ -0,0 +1,37 @@ +/* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Cl= ause) */ +/* Do not edit directly, auto-generated from: */ +/* Documentation/netlink/specs/binder.yaml */ +/* YNL-GEN uapi header */ + +#ifndef _UAPI_LINUX_ANDROID_BINDER_NETLINK_H +#define _UAPI_LINUX_ANDROID_BINDER_NETLINK_H + +#define BINDER_FAMILY_NAME "binder" +#define BINDER_FAMILY_VERSION 1 + +enum { + BINDER_A_REPORT_ERROR =3D 1, + BINDER_A_REPORT_CONTEXT, + BINDER_A_REPORT_FROM_PID, + BINDER_A_REPORT_FROM_TID, + BINDER_A_REPORT_TO_PID, + BINDER_A_REPORT_TO_TID, + BINDER_A_REPORT_IS_REPLY, + BINDER_A_REPORT_FLAGS, + BINDER_A_REPORT_CODE, + BINDER_A_REPORT_DATA_SIZE, + + __BINDER_A_REPORT_MAX, + BINDER_A_REPORT_MAX =3D (__BINDER_A_REPORT_MAX - 1) +}; + +enum { + BINDER_CMD_REPORT =3D 1, + + __BINDER_CMD_MAX, + BINDER_CMD_MAX =3D (__BINDER_CMD_MAX - 1) +}; + +#define BINDER_MCGRP_REPORT "report" + +#endif /* _UAPI_LINUX_ANDROID_BINDER_NETLINK_H */ --=20 2.50.1.470.g6ba607880d-goog From nobody Mon Oct 6 01:23:45 2025 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) (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 4310B220F49 for ; Sun, 27 Jul 2025 18:31:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753641086; cv=none; b=TEy+8WsgY6IEthtDJqZZrAWLYem21oNqkt/o7LPq2MiwsBb6ckjlM7/Sy8E7sTFgDfaeuwFMTUxV9nSWNhK3U0TI5nzu1WW1AIrzxqEtl7r+EZgkl0MdfmolB79NKn81Et6ecWT/InymL/9Ap3uXH3Svw6H8wo2pYzTWnKQLQIA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753641086; c=relaxed/simple; bh=w3B6eMOHBjLahJirDSZ+qk4aNUA7eTY19kZ8xkUuHVM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Kzs9bjzqm46C+9ATos+dlWX+/xn505eeYoUFa8q5VsT2kruKUQ8ylI7/3YBZz3UYX7FKX6SrJmdafku4o+eoa7u8HlWlUy+jmgFFns+f1aPdst2qffsVxTNH0h7NBU0jYdY8+t3yny0HKAFkfW3WzM4izxqpGY8ppjxEIUOCDsY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--cmllamas.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=LgvT6aLX; arc=none smtp.client-ip=209.85.215.201 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--cmllamas.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="LgvT6aLX" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-b2c00e965d0so2316319a12.2 for ; Sun, 27 Jul 2025 11:31:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1753641085; x=1754245885; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=0tolIyg+onFM/Vs+iMbCZXFo1uDxs6ZbvglnTYfZXx4=; b=LgvT6aLX9lsPIXqZIjYWKgCOwnW1+MqOHBPv03ZfDNxQrvhaqAKgV3K9AHTcsRRKt4 Jb17xAjhTT3N6ZkmwQaQGwsvrjIgalfGU7FWKAK75LGFTONRw0XSYDXKv5qlsEtM/AxA M43KknNvk8lWHLNKMKDoYbVTqEX839w8w1dngBoBxbmhfvkLnUcOAdVHtSHRS74l90Rv aMN571ypy4qc6B5Tru47ixNonbgxAYtcEAJmAibNmX5UA0FkmXNVQcYXHgzUKqL+THRC 6iOu82W3MoHCW65t0zffOR0n0sOaMA5aMXdEssqAljBvRVPOOdV0bRFbCJ0j+dJl0h7J 7r9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753641085; x=1754245885; h=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; bh=0tolIyg+onFM/Vs+iMbCZXFo1uDxs6ZbvglnTYfZXx4=; b=aGQ0G3j0xqA9HgucRpcirVTtb0h9zsoKluav32TF24i+e/sHBMgQaEBNHRfkTpQPDX 3dYy9lax+/LGEFMV+zVOcZ+JPN2qZ7kqR4n/xEeDWpN2lbVyx9QVKbxqUQPB5ExlaxSq SSoX+nN/d2J+0gZfL/hdulimjdD3UewIXmkYKd2LCm37imb++7zFTwdwvMdTNPjUf4ea weTocLfRvhU7gUexxRPlox9aNvg7EVc+t4XEOmD4hg8L5hSu28ktpPXAh0Pv1Qw3IMKg +JwU1+8tLW7k2FHQSCzwYjwcoAstCeB+iWA7g0G18e4j9JL7ZRbkNFDmnFvw51paqUk6 iq6g== X-Forwarded-Encrypted: i=1; AJvYcCUnsZpBrrYpuK36534FON6kydEKXTnp1Mwy9zItMGQu7y8YUt8x41W34ZnVEML/Vk9zTStK0gBC94COQ2I=@vger.kernel.org X-Gm-Message-State: AOJu0YxmA+zIqe4PvsOmmEmmyoANnDNeTOCIJbIhN/1l2n+4Kh4MLzga IvzZTV6vS3jquwDQdJ38OqeyjefZ4l6UtEoAQR2sgWAn1cryN6Zqdi0YRQ0xvKTu2cflF+CLd4K lqEfBpQcAHyEJvw== X-Google-Smtp-Source: AGHT+IEQHqngoylopHIEAU2iEAMut1Zbzg+THKSOuB5j9p86YjEG5k2zNo4IKpW3ZITBc5cTnIROU4PiqQ1e0g== X-Received: from pgar12.prod.google.com ([2002:a05:6a02:2e8c:b0:b31:c7e5:6665]) (user=cmllamas job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:430f:b0:222:d191:5bbd with SMTP id adf61e73a8af0-23d70217188mr14873947637.39.1753641084705; Sun, 27 Jul 2025 11:31:24 -0700 (PDT) Date: Sun, 27 Jul 2025 18:29:07 +0000 In-Reply-To: <20250727182932.2499194-1-cmllamas@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250727182932.2499194-1-cmllamas@google.com> X-Mailer: git-send-email 2.50.1.470.g6ba607880d-goog Message-ID: <20250727182932.2499194-5-cmllamas@google.com> Subject: [PATCH v20 4/5] binder: add transaction_report feature entry From: Carlos Llamas To: Alice Ryhl , Greg Kroah-Hartman , "=?UTF-8?q?Arve=20Hj=C3=B8nnev=C3=A5g?=" , Todd Kjos , Martijn Coenen , Joel Fernandes , Christian Brauner , Carlos Llamas , Suren Baghdasaryan , Shuah Khan , Yu-Ting Tseng , Li Li , Ba Jing Cc: Tiffany Yang , John Stultz , Shai Barack , "=?UTF-8?q?Thi=C3=A9baud=20Weksteen?=" , kernel-team@android.com, linux-kernel@vger.kernel.org, Jakub Kicinski , "open list:KERNEL SELFTEST FRAMEWORK" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Li Li Add "transaction_report" to the binderfs feature list, to help userspace determine if the "BINDER_CMD_REPORT" generic netlink api is supported by the binder driver. Signed-off-by: Li Li Signed-off-by: Carlos Llamas --- drivers/android/binderfs.c | 8 ++++++++ .../selftests/filesystems/binderfs/binderfs_test.c | 1 + 2 files changed, 9 insertions(+) diff --git a/drivers/android/binderfs.c b/drivers/android/binderfs.c index 4f827152d18e..f74a7e380261 100644 --- a/drivers/android/binderfs.c +++ b/drivers/android/binderfs.c @@ -59,6 +59,7 @@ struct binder_features { bool oneway_spam_detection; bool extended_error; bool freeze_notification; + bool transaction_report; }; =20 static const struct constant_table binderfs_param_stats[] =3D { @@ -76,6 +77,7 @@ static struct binder_features binder_features =3D { .oneway_spam_detection =3D true, .extended_error =3D true, .freeze_notification =3D true, + .transaction_report =3D true, }; =20 static inline struct binderfs_info *BINDERFS_SB(const struct super_block *= sb) @@ -616,6 +618,12 @@ static int init_binder_features(struct super_block *sb) if (IS_ERR(dentry)) return PTR_ERR(dentry); =20 + dentry =3D binderfs_create_file(dir, "transaction_report", + &binder_features_fops, + &binder_features.transaction_report); + if (IS_ERR(dentry)) + return PTR_ERR(dentry); + return 0; } =20 diff --git a/tools/testing/selftests/filesystems/binderfs/binderfs_test.c b= /tools/testing/selftests/filesystems/binderfs/binderfs_test.c index 81db85a5cc16..39a68078a79b 100644 --- a/tools/testing/selftests/filesystems/binderfs/binderfs_test.c +++ b/tools/testing/selftests/filesystems/binderfs/binderfs_test.c @@ -65,6 +65,7 @@ static int __do_binderfs_test(struct __test_metadata *_me= tadata) "oneway_spam_detection", "extended_error", "freeze_notification", + "transaction_report", }; =20 change_mountns(_metadata); --=20 2.50.1.470.g6ba607880d-goog From nobody Mon Oct 6 01:23:45 2025 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) (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 A2E8122A7E0 for ; Sun, 27 Jul 2025 18:31:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753641089; cv=none; b=gkNGcSChT72kjO77GDDj153639ZpfQQnAQXrPc+leLrvBNZv7twWji1tXd8GJXtt0kNPaMbdcbq/OZX0VPINdU3kLLksBL7DIZuSaUF7Z1xOeQsf05/uj03/mFouNZPLk49/2nv9h36NM7Jsrng3ZydZhaLEIrUnYmBRhol8+08= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753641089; c=relaxed/simple; bh=HNdw2Y2WCnhZqIPQ+M+4zVLBT3PzyW7Ihk8KCE6gAxo=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=flnSgobqLq2rfQi0N70/iOHxf5bWycwhHK3E6LLfQhWVQpdPxRNoz816rS4Vs8At63XtpFEi4HZXgktH3jBdPq5/q4tp4PuRn7qAbozkn4Bn5Q8t6yYQE2NPJSoLWBr7MTataTrXo8Sbbypjr/gwU0WzXCUgSDl76zK5uAzSpv8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--cmllamas.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=0Fx0iJTk; arc=none smtp.client-ip=209.85.214.201 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--cmllamas.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="0Fx0iJTk" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-23fc5b1c983so11961735ad.0 for ; Sun, 27 Jul 2025 11:31:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1753641087; x=1754245887; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=BtHJWM2gXUsv6xzq7C6P5vZ0vTx2NB+Xsxgc7a7A5cA=; b=0Fx0iJTkQHtTnn/vAyXrQxjWwCK7NIgVZh7BDVGyUPUexPnGLkchy7v8TkgSZRZBKR KnANgYeGjX1SPp2kBEaj7spxJ6YY3eLQ48//GnFMUOtHYnt0veL9DN9qB0FrSeDuJ7Mu Mbp+oJXW4/HCCvLH0nXp87DfxhOjYKw5rx2/VrxYFN7cWd6bMfybrm2kCNNKQaPpgiiP 1hbUAP/U9LHPMLd04mLP4WEzHO4hytRcnYYNl9qPnw+xx1A4DdzpILBiHr8Oy4t7DxbL CvxA62/8AfY/ON8CHkJccOY+QgAqqEId357w83996Sv1jjTKcEo/okqXekzJwlHm5aH3 6YBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753641087; x=1754245887; h=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; bh=BtHJWM2gXUsv6xzq7C6P5vZ0vTx2NB+Xsxgc7a7A5cA=; b=v6TPf/wTo4yEaIKAxo57cfEqMEpmdqIHJtU3JrL8K64i3l/zSMZc/NZDK7yxisKIlT RIPmfvbEnEL2DW2GOGsUfI2Qp5Qj6IiZRukFX4aRAlSvOkSx6QRPqe533UpAHLYMnmO1 dWNfkYT+vz84YZJwbdzF9FS5pnBCK/9lb4c3FgjhlIYXw4mPpm66ssnNy+PdI43FK1EX lfA+a+M5i9BMQG/rHdpp2XoZ0X2wRrf2cn0CgUEcNesrPsGXCbD1Z9jS7rtb8KLXd2I6 e7ZQFqDjidqE9b0PhVeZ3lNgceH6+09QT3R/sEigExJIZC2vzPk1BNkmRl6zm6AeeQ6d oI8w== X-Forwarded-Encrypted: i=1; AJvYcCX6jX9c+DsXjkZ9cWlXmpIsUp6UqdmcBGG1pE9wxrC8NzszVEotGpcrGpYMjxQHQz/Xa0bOHa82YkPq3XE=@vger.kernel.org X-Gm-Message-State: AOJu0Yy3ed5JgwaQLrqhbM8gM5mPOdPpVVYWO/AuxNbwxOml01L2c9Qk 1XkammcctineheLvRhbZDTGjGIaL8Gp8N4Dn0QaO+D5YsREUm8n6nNRJ6DaPr3z9bm9iibS3VSx BYBKUN7nximTt4A== X-Google-Smtp-Source: AGHT+IG8Z/EDkUlGuSIQr6Lxryh0dNjc5GK140pZ00kEg37MPO71RZjRx9AJ3+o8Ml6tBRZwKG6UvndyiMjhgA== X-Received: from plbka12.prod.google.com ([2002:a17:903:334c:b0:23f:b150:396e]) (user=cmllamas job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:2a88:b0:234:9fe1:8fc6 with SMTP id d9443c01a7336-23fa5da5ea6mr191691345ad.18.1753641086890; Sun, 27 Jul 2025 11:31:26 -0700 (PDT) Date: Sun, 27 Jul 2025 18:29:08 +0000 In-Reply-To: <20250727182932.2499194-1-cmllamas@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250727182932.2499194-1-cmllamas@google.com> X-Mailer: git-send-email 2.50.1.470.g6ba607880d-goog Message-ID: <20250727182932.2499194-6-cmllamas@google.com> Subject: [PATCH v20 5/5] binder: add tracepoint for netlink reports From: Carlos Llamas To: Alice Ryhl , Greg Kroah-Hartman , "=?UTF-8?q?Arve=20Hj=C3=B8nnev=C3=A5g?=" , Todd Kjos , Martijn Coenen , Joel Fernandes , Christian Brauner , Carlos Llamas , Suren Baghdasaryan Cc: Tiffany Yang , John Stultz , Shai Barack , "=?UTF-8?q?Thi=C3=A9baud=20Weksteen?=" , kernel-team@android.com, linux-kernel@vger.kernel.org, Jakub Kicinski Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a tracepoint to capture the same details that are being sent through the generic netlink interface during transaction failures. This provides a useful debugging tool to observe the events independently from the netlink listeners. Signed-off-by: Carlos Llamas --- drivers/android/binder.c | 2 ++ drivers/android/binder_trace.h | 37 ++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/drivers/android/binder.c b/drivers/android/binder.c index 0d37eca514f9..695c1631703b 100644 --- a/drivers/android/binder.c +++ b/drivers/android/binder.c @@ -3014,6 +3014,8 @@ static void binder_netlink_report(struct binder_proc = *proc, BINDER_NLGRP_REPORT)) return; =20 + trace_binder_netlink_report(context, t, data_size, error); + skb =3D genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_KERNEL); if (!skb) return; diff --git a/drivers/android/binder_trace.h b/drivers/android/binder_trace.h index 97a78e5623db..fa5eb61cf580 100644 --- a/drivers/android/binder_trace.h +++ b/drivers/android/binder_trace.h @@ -402,6 +402,43 @@ TRACE_EVENT(binder_return, "unknown") ); =20 +TRACE_EVENT(binder_netlink_report, + TP_PROTO(const char *context, + struct binder_transaction *t, + u32 data_size, + u32 error), + TP_ARGS(context, t, data_size, error), + TP_STRUCT__entry( + __field(const char *, context) + __field(u32, error) + __field(int, from_pid) + __field(int, from_tid) + __field(int, to_pid) + __field(int, to_tid) + __field(bool, is_reply) + __field(unsigned int, flags) + __field(unsigned int, code) + __field(size_t, data_size) + ), + TP_fast_assign( + __entry->context =3D context; + __entry->error =3D error; + __entry->from_pid =3D t->from_pid; + __entry->from_tid =3D t->from_tid; + __entry->to_pid =3D t->to_proc ? t->to_proc->pid : 0; + __entry->to_tid =3D t->to_thread ? t->to_thread->pid : 0; + __entry->is_reply =3D t->is_reply; + __entry->flags =3D t->flags; + __entry->code =3D t->code; + __entry->data_size =3D data_size; + ), + TP_printk("from %d:%d to %d:%d context=3D%s error=3D%d is_reply=3D%d flag= s=3D0x%x code=3D0x%x size=3D%zu", + __entry->from_pid, __entry->from_tid, + __entry->to_pid, __entry->to_tid, + __entry->context, __entry->error, __entry->is_reply, + __entry->flags, __entry->code, __entry->data_size) +); + #endif /* _BINDER_TRACE_H */ =20 #undef TRACE_INCLUDE_PATH --=20 2.50.1.470.g6ba607880d-goog