From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.200 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796344387; b=aZEUcBxZ8psQOPIoLRimuZH6Q4zG5BvUWGmixVNUTVCWGwB5F9Xb38cGppoe3DdtFlvZ x3kdZN/qrSKi8H71wwgWCYa7grzVulZQ57037CrGB3kpYLpJmSliIXyW3r23ExRc6nSaX IO5TcOkCJqDZce2QK4pmytl3JQ+g7tLPMR42F8PC2JsyJlRf/6FSD5I7O2kQOsV1nfxqq Ph3wVbvsYK/1Gc9vd1UzbBomqsS1lhdLddDgfygU+DSq0g8SWeer9pkCOg/6Ku3eVnI6a KpSJZujGJ2t0oOVyvtXjiLYJLxDNtP3eZxQ6AbqVrShES5yVsYRlIH5M/DemkHXXCOw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796344387; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:Mime-Version: X-B4-Tracking:X-Change-Id:X-Developer-Key:X-Developer-Signature: X-Mailer:Message-ID:Subject:From:To:Cc:Content-Type; bh=Gdr81bmrhFd56H9BbZIrTo5pht4eFw10fNvdVoszRr4=; b=OICXLbblDXjXxFu/hTHhOSbDrgg5ESHjixNIryRRFQmsYIhQScbjUe1HUQ0hTksV2Fha BKbnRDleBU1lFRIsg8RHfwkfmEYcK9XdUvPBj67NXUGpk4i4Ab2G82JylKlQSAPMpJRE8 sRblQGLBUe1skAxWg6ZVYOJIrNHL3tBBVwixoQnX6wSpuVEt5yR89LZdQJfl0L8ypVq2v JuMWhQvQQvXalLMQscTXK5stYdhrAEk0UvPY4+M3ooW1cCpANj1rP+EYqViDM8r8Xwsb3 B9TaKTAAUf1UTr0eR6PbKkIOEh5KW/lZe736kh7Vea9lbn4LioNWMvjxQPjn301tevQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--grahalt.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=W9bGbwqn; arc=none smtp.remote-ip=209.85.214.200 Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1DCED606A32C for ; Fri, 4 Dec 2026 00:33:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 1DCED606A32C 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--grahalt.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=W9bGbwqn Received: by mail-pl1-f200.google.com with SMTP id d9443c01a7336-2f0e3ffabe0so2456235ad.0 for ; Thu, 03 Dec 2026 16:33:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796344385; x=1796949185; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:mime-version:date:from :to:cc:subject:date:message-id:reply-to:content-type; bh=Gdr81bmrhFd56H9BbZIrTo5pht4eFw10fNvdVoszRr4=; b=W9bGbwqnLYYikg1dqZ5rszNDUZzBoZt5QSCs2SXolHEBKLfJoQtUYv4MpREkhytUzB 7QfrmxgTmj2ZiCDRp8pkN49OFnKVClP2L8hJb6KnjvQFl1NR28yKjzVHmmiG0dyZ7GCj hVCOZjXBypG18dBhl9gPSNyhhWKJh2VZJAcjg8MTt95YetZULUau1k91YnXUjTqFiSZH QrNr8zrTkDrvM+UzQ4W5McWkBj9AyHjVMagB4jMl9qed6xBwHUlaP1l/loniYjfYktjc 670i07fjrb/mawyZsFH7zoLSFrW0a6WzVdcJFSRNlAsmjGqxmWcisc8RVdh8hMFb/uIG h9AA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796344385; x=1796949185; h=content-type:cc:to:from:subject:message-id:mime-version:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=Gdr81bmrhFd56H9BbZIrTo5pht4eFw10fNvdVoszRr4=; b=SKVHvmQjBkCYPTNGxAMVirfkxHGl46oYiZlI8qKNadnadxxA7Ikq1B30+NA7kagWdZ +cSBA0V+CvG8mh/XtRcpTts+ZQoVATWGIiMqfRvv31bXVm2rFhWsdlLIXGe+TmuFqnB/ crk+0qEWU/eMJupVXSgIPmX4ns4XeenvfZwNuFeObyOXEt3bMdyYLmtRBD/uppx7t1Ac BHWiwi8Cff+FqOvQB+lPABdek44P7PeYMd4Yw9Ch4fyicCBgvmRt168T6pL8nVK6ozO8 AAVp4jV6MU8rDZvT2rdgVRG19eZBjuAkCDJwZQurA5pkHr30+/+Jj/M39j0qEQM7T7A5 lGAA== X-Forwarded-Encrypted: i=1; AL+hErH1rZg8yW0gIUyKLYqKpDy4eKdgug7Ad0NENKSM4uh1Grb08gEbqXMqJiKhJ5KcZMMfXI50YCcFg6g=@vger.kernel.org X-Gm-Message-State: APuU4Z+ZTb7dGKXcI3XaOj+bwJoz4FWZRtWrbp5rDuYfH8M83czQKd01 D/mRuiQRqNxRpNkxIwcgy4VGCC5iPXKGqJbKZDWJLq3IGnUTijZU6cGK91XNKpKUobM21iT8eS0 CI2fVt9GsgQ== X-Received: from plbmo16.prod.google.com ([2002:a17:903:a90:b0:2f0:4ed9:64dd]) (user=grahalt job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:ef46:b0:2f0:dbe8:bb7d with SMTP id d9443c01a7336-2f1ba224d08mr2258685ad.53.1796344385116; Thu, 03 Dec 2026 16:33:05 -0800 (PST) Date: Fri, 04 Dec 2026 00:32:45 +0000 X-Mailing-List: linux-api@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 X-B4-Tracking: v=1; b=H4sIAC0KEmsC/x3MMQ6DMAwAwK8gz7WUBJqm/QpigMaAl4BsaJFQ/ k7EeMudoCRMCp/qBKEfKy+pwD4q+M59mgg5FoMzzlvjAsquGw6cIglus1AfUdfC5Z+wsU14PX3 w9dtBGVahkY97b7ucL98ID7dtAAAA X-Change-Id: 20261028-rust-binder-thread-spindown-414875686392 X-Developer-Key: i=grahalt@google.com; a=ed25519; pk=Fdl8UB2iAFT3+RcdOulskhAYycOow7vcBsXiopOEuZQ= X-Developer-Signature: v=1; a=ed25519-sha256; t=1796344384; l=5289; i=grahalt@google.com; s=20261202; h=from:subject:message-id; bh=2ayv7Gwsf+9oK6BwHkB6Y6q28NdQVoteHK5rV0ednCI=; b=sKxbZgaPap8/c+8rjYIiuZPsr54J5OQBmJdiI3OvyQU6aK57us/vkF7Q8pXdyGJuR0tH40QfQ RjXlnObSHjqDYu5f1BtoZDKkof2S5ekwnfkX7kx4rbWThRLqZu5ZneM X-Mailer: b4 0.14.3 Message-ID: <20261204-rust-binder-thread-spindown-v1-0-8702c42d4437@google.com> Subject: [PATCH 0/4] rust_binder: add support for idle thread timeout From: Nicholas Giunta To: Greg Kroah-Hartman , Carlos Llamas , Alice Ryhl , "=?utf-8?q?Arve_Hj=C3=B8nnev=C3=A5g?=" , Todd Kjos , Christian Brauner , Boqun Feng , Gary Guo , Miguel Ojeda , Shuah Khan Cc: Lyude Paul , Daniel Almeida , "=?utf-8?q?Onur_=C3=96zkan?=" , "=?utf-8?q?Bj=C3=B6rn_Roy_Baron?=" , Benno Lossin , Andreas Hindborg , Trevor Gross , Danilo Krummrich , Tamir Duberstein , Alexandre Courbot , linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-api@vger.kernel.org, Nicholas Giunta Content-Type: text/plain; charset="utf-8" This series adds opt-in per-process idle thread timeout support to the Rust Binder driver using the existing BINDER_SET_IDLE_TIMEOUT ioctl and BR_FINISHED return command, along with kselftest coverage in binderfs_test. Today, extra binder looper threads spawned via BR_SPAWN_LOOPER remain blocked waiting for work indefinitely even after bursts of IPC traffic subside, preventing userspace from terminating idle threads and reclaiming their resources. With Android's libbinder default of 15 max threads, this can leave up to 15 extra threads per process parked in the binder driver. With this series, a process can opt into idle thread spin-down by configuring a millisecond timeout via BINDER_SET_IDLE_TIMEOUT (defaulting to disabled, Delta::ZERO). Only registered looper threads spawned via BR_SPAWN_LOOPER are eligible to time out; main threads registered with BC_ENTER_LOOPER and polling threads remain exempt. To keep at least one ready thread warm for incoming work, a thread whose timeout expires while it is the sole entry in ready_threads defers its timeout until either a peer joins ready_threads (waking it via notify_if_deferred_timeout() so it exits with BR_FINISHED, unless timeout was disabled at runtime) or incoming work arrives (waking it via push_work_inner() to deliver the transaction instead). On timeout returns, BR_SPAWN_LOOPER is suppressed, and Process::remove_thread() decrements started_thread_count on BINDER_THREAD_EXIT so threads can be respawned when demand returns. Series overview: 1. rust: sync: condvar: add wait_interruptible_freezable_timeout() Adds a freezable interruptible condvar wait with timeout so Rust Binder threads can time out while still allowing process freeze. 2. rust_binder: add support for thread timeout Implements BINDER_SET_IDLE_TIMEOUT, BR_FINISHED spin-down, sole-ready-thread timeout deferral, started_thread_count accounting on BC_REGISTER_LOOPER / BINDER_THREAD_EXIT, and UAPI docs in include/uapi/linux/android/binder.h. 3. selftests/binderfs: extract shared namespace and mount helpers Factors out duplicated userns, binderfs mount/unmount, and binder-control device allocation helpers across existing tests. 4. selftests/binderfs: add idle timeout tests Adds FIXTURE(binderfs_idle) tests covering default-disabled behavior, ioctl validation and runtime reset, spin-down/respawn cycles, BC_ENTER_LOOPER immunity, and sole-ready-thread retention (with automatic SKIP on kernels without idle timeout support). Base and routing: This series is based on char-misc-next, commit 86266f137b5c ("rust_binder: fix process leak on proc file creation failure"). Patch 1 touches rust/kernel/sync/condvar.rs and Patches 3-4 touch tools/testing/selftests/filesystems/binderfs/binderfs_test.c; if acceptable to the Rust sync and kselftest maintainers, Acked-by tags would allow the full series to go through char-misc-next together. Testing: - scripts/checkpatch.pl --strict (clean except for the expected Assisted-by: tag), make LLVM=1 rustfmtcheck, make LLVM=1 CLIPPY=1, and make LLVM=1 rusttest (6 passed; 0 failed). - x86_64 QEMU+KVM with CONFIG_USER_NS=y, lockdep, and KUnit enabled (CONFIG_PROVE_LOCKING=y, CONFIG_DEBUG_ATOMIC_SLEEP=y, CONFIG_FREEZER=y, CONFIG_KUNIT=y, CONFIG_RUST_KUNIT_TESTS=y): - rust_kernel_time KUnit suite passed (2/2, covering Delta::to_jiffies_timeout()). - Full tools/testing/selftests/filesystems/binderfs/binderfs_test (binderfs_stress, binderfs_test_privileged, binderfs_test_unprivileged, and binderfs_idle.*): 3 consecutive root runs (6/6 passed each) and 2 consecutive non-root runs (5/6 passed + 1 expected privileged skip each) with zero lockdep or atomic-sleep warnings. - Cuttlefish Android GKI runs and Android binder integration test suites (default-disabled regression coverage). Tooling disclosure (Documentation/process/generated-content.rst): An AI coding assistant (Gemini) was used to help review concurrency edge cases (including sole-ready-thread timeout deferral), refactor and write the binderfs_test.c selftests, and draft commit messages and this cover letter. All code and descriptions were reviewed, built, and verified by the submitter. Signed-off-by: Nicholas Giunta --- Nicholas Giunta (4): rust: sync: condvar: add wait_interruptible_freezable_timeout() rust_binder: add support for thread timeout selftests/binderfs: extract shared namespace and mount helpers selftests/binderfs: add idle timeout tests drivers/android/binder/defs.rs | 1 + drivers/android/binder/process.rs | 110 ++- drivers/android/binder/thread.rs | 117 ++- include/uapi/linux/android/binder.h | 14 +- rust/kernel/sync/condvar.rs | 47 +- .../selftests/filesystems/binderfs/binderfs_test.c | 862 +++++++++++++++------ 6 files changed, 881 insertions(+), 270 deletions(-) --- base-commit: 86266f137b5c18d477a2df8168149203852b037d change-id: 20261028-rust-binder-thread-spindown-414875686392 Best regards, -- Nicholas Giunta