From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.197 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796344387; b=O3k7uZZH9eNY8tI8JQ5hO5Jpu8+A+xje5sZiht0OVOyyA8gAY+aHRmvJvBHjphc3wivV tnYIjRbLrRBzmFTpOEWcmk6dojJecBfOTfL1PD0rBYzsNhkNjT4EVdYyFXKTDiTGL00t/ 1LnMd2NT+EIntCfMrjjcgaWPTc4cRH3fSOOJky8w6dlesHA70u1VPtUzMiiM7Iui0r9dJ k68X4CLF0BNDz7gEmE+3jSlGRFxirTFYsU8gfSgqEgAmCHJL/cZ2ewPPmIR8pxxKM4Sa7 hgD+GOMAhVucRxpN8vS7soGqpcQ0icC1KdGNbX8TPMmNEw9+xMfNIfWxrL792G4I3YQ== 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=FXIvFjEDO19rAQN1Br54QVXHiDcC3P5m4p1xbnhZhmiePwn27M6kyfBNBEITwKfOjQXN nZp53O4YDiAVcL6nkJKp/qW0Mz6EU8JUiNo1LMAcIMMB57RPds2CsxszoF3o2muOqyKC6 2L7353u9VesPkq6TePHpOM1uu8Tmr5anoqcwu3WlYp9Tqr7ElZgEFbVnEHqf9yWGSJKVr N8xoUeqv19PG4U84k3msX5oYczupeHtOgFGgoAqphvzbP6Ju2cufGEc0Xe8dQF+69AYYE SlNHIbbh6to2Ja5Nw1JeEp9OfpN0838hOiu2tDfea+8BlGkReoi2m8oYX3jmmU0F7cQ== 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.197 Received: from mail-pl1-f197.google.com (mail-pl1-f197.google.com [209.85.214.197]) (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 16B3F606A322 for ; Fri, 4 Dec 2026 00:33:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 16B3F606A322 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-f197.google.com with SMTP id d9443c01a7336-2f045e399acso1597495ad.2 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=UsNQf1ya6ZHaIUIXpNBkq8F6ZBjjOfayUd5qPi7WWINYGNxk3EzSOSZqx3I2v2v9j+ 8jxLTlyH1lC2/nKRrjtx32lMUVfNfPp/TuVG5roZATHe1J+HnOPYGOSnq8G/YRR3HqHW AYXM3tYsJXn5pPrqEhpOOyVUDghY5X7yU5uljn+WvqMNd5OOGDD9QCDO16uAO7VU0R2j fQGpiyVfxDl5QVSvT3KQXNj7xKzYIJiQw9LrnQuYAJeF4Q7AArJV9D32+TFwEmJyMM5c JHXoMIp9Xv3sVydNHwGiVO7z0Ts9vY2/XwMIppnuoIxTNmX3fbLtjobOBAmhQNQphFqN 4iIQ== X-Forwarded-Encrypted: i=1; AL+hErGfJkBDbpRhQ9zMhcDrPlk59ERtx5ESlvJFWBkrzsLPS8hYMZV20gJuKOB9EU2gXcX0RnFFVlWqEo/WJF4=@vger.kernel.org X-Gm-Message-State: APuU4Z/NX3NIXkWPpRNI4oJb8OSQw//aM52HLkPl51p5GRLyjoXnqijT rXTa2YyGgevEcNGdkxagV1FRGlzBdHnWAN4JaBNdGoYlYa5PtJP4J8WVLATYrcnDcVbtzGswXyg 74HiXQ2FEsg== 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-kernel@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