mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Adhyansh Verma <adhyanshverma2010@gmail.com>
To: Alice Ryhl <aliceryhl@google.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Carlos Llamas <cmllamas@google.com>
Cc: "Arve Hjønnevåg" <arve@android.com>,
	"Todd Kjos" <tkjos@android.com>,
	"Christian Brauner" <brauner@kernel.org>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] rust_binder: decrement requested_thread_count on BR_SPAWN_LOOPER write failure
Date: Sat, 28 Nov 2026 21:07:19 +0530	[thread overview]
Message-ID: <20261128153719.143637-1-adhyanshverma2010@gmail.com> (raw)

In Thread::read(), when more threads are needed for the binder thread pool,
self.process.needs_thread() is called to request a new looper thread.
needs_thread() checks that requested_thread_count is 0, and if so,
increments it to 1.

Subsequently, writer.write(&BR_SPAWN_LOOPER) writes the command to the
userspace read buffer. If this write fails (for example, if userspace
provided an invalid or faulting address), the error is propagated using
the '?' operator. However, requested_thread_count is never decremented on
failure.

Because userspace never received the BR_SPAWN_LOOPER command, it will
never register a new thread via BC_REGISTER_LOOPER (which is the only
place where requested_thread_count is decremented). Consequently,
requested_thread_count remains permanently set to 1. Any subsequent calls
to needs_thread() will see requested_thread_count != 0 and return false,
permanently starving the process binder thread pool from spawning looper
threads.

This mirrors the C Binder driver (drivers/android/binder.c), which
explicitly decrements proc->requested_threads if put_user(BR_SPAWN_LOOPER)
fails.

Introduce undo_needs_thread() on Process to decrement
requested_thread_count if the BR_SPAWN_LOOPER write fails.

Fixes: eafedbc7c050 ("rust_binder: add Rust Binder driver")
Signed-off-by: Adhyansh Verma <adhyanshverma2010@gmail.com>
---
 drivers/android/binder/process.rs | 7 +++++++
 drivers/android/binder/thread.rs  | 5 ++++-
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/drivers/android/binder/process.rs b/drivers/android/binder/process.rs
index 1f4cb43f1de..a6d49e7dd84 100644
--- a/drivers/android/binder/process.rs
+++ b/drivers/android/binder/process.rs
@@ -1269,6 +1269,13 @@ pub(crate) fn needs_thread(&self) -> bool {
         ret
     }
 
+    pub(crate) fn undo_needs_thread(&self) {
+        let mut inner = self.inner.lock();
+        if inner.requested_thread_count > 0 {
+            inner.requested_thread_count -= 1;
+        }
+    }
+
     pub(crate) fn request_death(
         self: &Arc<Self>,
         reader: &mut UserSliceReader,
diff --git a/drivers/android/binder/thread.rs b/drivers/android/binder/thread.rs
index 4ce6fc53320..d36ecd12dfe 100644
--- a/drivers/android/binder/thread.rs
+++ b/drivers/android/binder/thread.rs
@@ -1658,7 +1658,10 @@ fn read(self: &Arc<Self>, req: &mut BinderWriteRead, wait: bool) -> Result {
                 req.read_size as usize,
             )
             .writer();
-            writer.write(&BR_SPAWN_LOOPER)?;
+            if let Err(err) = writer.write(&BR_SPAWN_LOOPER) {
+                self.process.undo_needs_thread();
+                return Err(err);
+            }
         }
         Ok(())
     }
-- 
2.56.1

             reply	other threads:[~2026-11-28 15:37 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-28 15:37 Adhyansh Verma [this message]
2026-11-29 10:35 ` Alice Ryhl

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261128153719.143637-1-adhyanshverma2010@gmail.com \
    --to=adhyanshverma2010@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=arve@android.com \
    --cc=brauner@kernel.org \
    --cc=cmllamas@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tkjos@android.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®