* [PATCH 1/4] rust: sync: condvar: add wait_interruptible_freezable_timeout()
2026-12-04 0:32 [PATCH 0/4] rust_binder: add support for idle thread timeout Nicholas Giunta
@ 2026-12-04 0:32 ` Nicholas Giunta
2026-12-04 0:32 ` [PATCH 2/4] rust_binder: add support for thread timeout Nicholas Giunta
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Nicholas Giunta @ 2026-12-04 0:32 UTC (permalink / raw)
To: Greg Kroah-Hartman, Carlos Llamas, Alice Ryhl,
Arve Hjønnevåg, Todd Kjos, Christian Brauner,
Boqun Feng, Gary Guo, Miguel Ojeda, Shuah Khan
Cc: Lyude Paul, Daniel Almeida, Onur Özkan,
Björn Roy Baron, Benno Lossin, Andreas Hindborg,
Trevor Gross, Danilo Krummrich, Tamir Duberstein,
Alexandre Courbot, linux-kernel, rust-for-linux, linux-kselftest,
linux-api, Nicholas Giunta
To support waiting on a condition variable with a timeout as a freezable
task, add CondVar::wait_interruptible_freezable_timeout().
Rust Binder requires this functionality to allow idle looper threads to
time out and spin down while still allowing processes to be frozen when
their threads are blocked in the binder driver.
Assisted-by: Gemini
Signed-off-by: Nicholas Giunta <grahalt@google.com>
---
rust/kernel/sync/condvar.rs | 47 ++++++++++++++++++++++++++++++++++++++-------
1 file changed, 40 insertions(+), 7 deletions(-)
diff --git a/rust/kernel/sync/condvar.rs b/rust/kernel/sync/condvar.rs
index 69d58dfbad7b..e5ddf7427eea 100644
--- a/rust/kernel/sync/condvar.rs
+++ b/rust/kernel/sync/condvar.rs
@@ -177,6 +177,22 @@ pub fn wait_interruptible_freezable<T: ?Sized, B: Backend>(
crate::current!().signal_pending()
}
+ fn wait_interruptible_timeout_internal<T: ?Sized, B: Backend>(
+ &self,
+ wait_state: c_int,
+ guard: &mut Guard<'_, T, B>,
+ jiffies: Jiffies,
+ ) -> CondVarTimeoutResult {
+ let jiffies = jiffies.try_into().unwrap_or(MAX_SCHEDULE_TIMEOUT);
+ let res = self.wait_internal(wait_state, guard, jiffies);
+
+ match (res as Jiffies, crate::current!().signal_pending()) {
+ (jiffies, true) => CondVarTimeoutResult::Signal { jiffies },
+ (0, false) => CondVarTimeoutResult::Timeout,
+ (jiffies, false) => CondVarTimeoutResult::Woken { jiffies },
+ }
+ }
+
/// Releases the lock and waits for a notification in interruptible mode.
///
/// Atomically releases the given lock (whose ownership is proven by the guard) and puts the
@@ -188,14 +204,31 @@ pub fn wait_interruptible_timeout<T: ?Sized, B: Backend>(
guard: &mut Guard<'_, T, B>,
jiffies: Jiffies,
) -> CondVarTimeoutResult {
- let jiffies = jiffies.try_into().unwrap_or(MAX_SCHEDULE_TIMEOUT);
- let res = self.wait_internal(TASK_INTERRUPTIBLE, guard, jiffies);
+ self.wait_interruptible_timeout_internal(TASK_INTERRUPTIBLE, guard, jiffies)
+ }
- match (res as Jiffies, crate::current!().signal_pending()) {
- (jiffies, true) => CondVarTimeoutResult::Signal { jiffies },
- (0, false) => CondVarTimeoutResult::Timeout,
- (jiffies, false) => CondVarTimeoutResult::Woken { jiffies },
- }
+ /// Releases the lock and waits for a notification in interruptible and freezable mode.
+ ///
+ /// Atomically releases the given lock (whose ownership is proven by the guard) and puts the
+ /// thread to sleep. It wakes up when notified by [`CondVar::notify_one`] or
+ /// [`CondVar::notify_all`], or when a timeout occurs, or when the thread receives a signal.
+ ///
+ /// The process is allowed to be frozen during this sleep. No lock should be held when calling
+ /// this function, and there is a lockdep assertion for this. Freezing a task that holds a lock
+ /// can trivially deadlock vs another task that needs that lock to complete before it too can
+ /// hit freezable.
+ #[must_use = "wait_interruptible_freezable_timeout returns if a signal is pending, \
+ so the caller must check the return value"]
+ pub fn wait_interruptible_freezable_timeout<T: ?Sized, B: Backend>(
+ &self,
+ guard: &mut Guard<'_, T, B>,
+ jiffies: Jiffies,
+ ) -> CondVarTimeoutResult {
+ self.wait_interruptible_timeout_internal(
+ TASK_INTERRUPTIBLE | TASK_FREEZABLE,
+ guard,
+ jiffies,
+ )
}
/// Calls the kernel function to notify the appropriate number of threads.
--
2.56.1.915.g69d5ec7298-goog
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH 2/4] rust_binder: add support for thread timeout
2026-12-04 0:32 [PATCH 0/4] rust_binder: add support for idle thread timeout Nicholas Giunta
2026-12-04 0:32 ` [PATCH 1/4] rust: sync: condvar: add wait_interruptible_freezable_timeout() Nicholas Giunta
@ 2026-12-04 0:32 ` Nicholas Giunta
2026-12-04 0:32 ` [PATCH 3/4] selftests/binderfs: extract shared namespace and mount helpers Nicholas Giunta
2026-12-04 0:32 ` [PATCH 4/4] selftests/binderfs: add idle timeout tests Nicholas Giunta
3 siblings, 0 replies; 5+ messages in thread
From: Nicholas Giunta @ 2026-12-04 0:32 UTC (permalink / raw)
To: Greg Kroah-Hartman, Carlos Llamas, Alice Ryhl,
Arve Hjønnevåg, Todd Kjos, Christian Brauner,
Boqun Feng, Gary Guo, Miguel Ojeda, Shuah Khan
Cc: Lyude Paul, Daniel Almeida, Onur Özkan,
Björn Roy Baron, Benno Lossin, Andreas Hindborg,
Trevor Gross, Danilo Krummrich, Tamir Duberstein,
Alexandre Courbot, linux-kernel, rust-for-linux, linux-kselftest,
linux-api, Nicholas Giunta
Allow idle registered binder looper threads to be terminated and have
their resources reclaimed using the existing BINDER_SET_IDLE_TIMEOUT
ioctl and BR_FINISHED return command, and document their semantics
(including runtime reconfiguration) in
include/uapi/linux/android/binder.h. Android's libbinder
(IPCThreadState::joinThreadPool()) already consumes BR_FINISHED by
breaking out of its looper loop and issuing BC_EXIT_LOOPER followed by
BINDER_THREAD_EXIT.
Per-process idle timeout defaults to disabled (Delta::ZERO) and can be
configured in milliseconds via BINDER_SET_IDLE_TIMEOUT (rejecting
negative values with EINVAL). 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.
When a thread's idle timeout expires while it is the sole thread in
ready_threads, retain it with a deferred timeout flag
(InnerThread::deferred_timeout / ProcessInner::has_deferred_timeout) so
at least one ready thread remains warm for incoming work; once a peer
joins ready_threads, notify the deferred thread to exit with BR_FINISHED
(or deliver incoming work if a transaction arrives first). Resetting
BINDER_SET_IDLE_TIMEOUT to 0 clears any active deferred timeout and
prevents waiting threads from spinning down.
Also suppress BR_SPAWN_LOOPER on timeout returns, guard
BC_REGISTER_LOOPER's register_thread() with !inner.is_looper() under
Process::inner -> Thread::inner while recording LooperFlag::Started, and
decrement started_thread_count in Process::remove_thread() only for
started loopers so spun-down threads can be respawned without leaking or
double-counting under duplicate or mixed looper commands.
Assisted-by: Gemini
Signed-off-by: Nicholas Giunta <grahalt@google.com>
---
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 ++++-
4 files changed, 220 insertions(+), 22 deletions(-)
diff --git a/drivers/android/binder/defs.rs b/drivers/android/binder/defs.rs
index cc4becd6e168..8c1d24e057f5 100644
--- a/drivers/android/binder/defs.rs
+++ b/drivers/android/binder/defs.rs
@@ -24,6 +24,7 @@ macro_rules! pub_no_prefix {
BR_REPLY,
BR_DEAD_REPLY,
BR_FAILED_REPLY,
+ BR_FINISHED,
BR_FROZEN_REPLY,
BR_NOOP,
BR_SPAWN_LOOPER,
diff --git a/drivers/android/binder/process.rs b/drivers/android/binder/process.rs
index e97213250beb..7f51a500707e 100644
--- a/drivers/android/binder/process.rs
+++ b/drivers/android/binder/process.rs
@@ -35,6 +35,7 @@
Arc, ArcBorrow, CondVar, CondVarTimeoutResult, SetOnce, SpinLock, UniqueArc,
},
task::{Pid, Task},
+ time::Delta,
uaccess::{UserSlice, UserSliceReader},
uapi,
workqueue::{self, Work},
@@ -130,6 +131,10 @@ pub(crate) struct ProcessInner {
max_threads: u32,
/// The number of threads the started and registered with the thread pool.
started_thread_count: u32,
+ /// The timeout duration that threads idle before being released via `BR_FINISHED`.
+ idle_timeout: Delta,
+ /// Whether the sole thread in `ready_threads` has a deferred idle timeout.
+ has_deferred_timeout: bool,
/// Bitmap of deferred work to do.
defer_work: DeferWorks,
@@ -162,6 +167,8 @@ fn new() -> Self {
requested_thread_count: 0,
max_threads: 0,
started_thread_count: 0,
+ idle_timeout: Delta::ZERO,
+ has_deferred_timeout: false,
defer_work: DeferWorks::default(),
outstanding_txns: 0,
is_frozen: IsFrozen::No,
@@ -190,6 +197,7 @@ pub(crate) fn push_work(
// Try to find a ready thread to which to push the work.
if let Some(thread) = self.ready_threads.pop_front() {
+ self.has_deferred_timeout = false;
// Push to thread while holding state lock. This prevents the thread from giving up
// (for example, because of a signal) when we're about to deliver work.
match thread.push_work_inner(work, sync) {
@@ -297,7 +305,11 @@ fn get_existing_node(&self, ptr: u64, cookie: u64) -> Result<Option<DArc<Node>>>
}
}
- fn register_thread(&mut self) -> bool {
+ pub(crate) fn idle_timeout(&self) -> Delta {
+ self.idle_timeout
+ }
+
+ pub(crate) fn register_thread(&mut self) -> bool {
if self.requested_thread_count == 0 {
return false;
}
@@ -708,7 +720,14 @@ pub(crate) fn get_work_or_register<'a>(
}
// Register the thread as ready.
- GetWorkOrRegister::Register(Registration::new(thread, &mut inner))
+ let mut deferred = None;
+ let reg = Registration::new(thread, &mut inner, &mut deferred);
+ let idle_timeout = inner.idle_timeout;
+ drop(inner);
+ if let Some(prev) = deferred {
+ prev.notify_if_deferred_timeout();
+ }
+ GetWorkOrRegister::Register(reg, idle_timeout)
}
fn get_current_thread(self: ArcBorrow<'_, Self>) -> Result<Arc<Thread>> {
@@ -1194,12 +1213,22 @@ fn version(&self, data: UserSlice) -> Result {
data.writer().write(&BinderVersion::current())
}
- pub(crate) fn register_thread(&self) -> bool {
- self.inner.lock().register_thread()
- }
-
fn remove_thread(&self, thread: Arc<Thread>) {
- self.inner.lock().threads.remove(&thread.id);
+ {
+ let mut inner = self.inner.lock();
+ if inner.threads.remove(&thread.id).is_some() && thread.is_started_looper() {
+ inner.started_thread_count = match inner.started_thread_count.checked_sub(1) {
+ Some(val) => val,
+ None => {
+ pr_warn_ratelimited!(
+ "started_thread_count underflow in pid: {}.\n",
+ self.pid_in_current_ns()
+ );
+ 0
+ }
+ };
+ }
+ }
thread.release();
}
@@ -1207,6 +1236,22 @@ fn set_max_threads(&self, max: u32) {
self.inner.lock().max_threads = max;
}
+ fn set_idle_timeout(&self, timeout: i64) -> Result {
+ if timeout < 0 {
+ return Err(EINVAL);
+ }
+ let timeout_duration = Delta::from_millis(timeout);
+ let mut inner = self.inner.lock();
+ inner.idle_timeout = timeout_duration;
+ if timeout_duration.is_zero() && inner.has_deferred_timeout {
+ if let Some(thread) = inner.ready_threads.iter().next() {
+ thread.clear_deferred_timeout();
+ }
+ inner.has_deferred_timeout = false;
+ }
+ Ok(())
+ }
+
fn set_oneway_spam_detection_enabled(&self, enabled: u32) {
self.inner.lock().oneway_spam_detection_enabled = enabled != 0;
}
@@ -1678,6 +1723,7 @@ fn ioctl_write_only(
let thread = this.get_current_thread()?;
match cmd {
uapi::BINDER_SET_MAX_THREADS => this.set_max_threads(reader.read()?),
+ uapi::BINDER_SET_IDLE_TIMEOUT => this.set_idle_timeout(reader.read()?)?,
uapi::BINDER_THREAD_EXIT => this.remove_thread(thread),
uapi::BINDER_SET_CONTEXT_MGR => this.set_as_manager(None, &thread)?,
uapi::BINDER_SET_CONTEXT_MGR_EXT => {
@@ -1833,13 +1879,22 @@ pub(crate) fn poll(
/// The destructor of this type will unregister the thread from the list of ready threads.
pub(crate) struct Registration<'a> {
thread: &'a Arc<Thread>,
+ unregistered: bool,
}
impl<'a> Registration<'a> {
- fn new(thread: &'a Arc<Thread>, guard: &mut Guard<'_, ProcessInner, SpinLockBackend>) -> Self {
+ fn new(
+ thread: &'a Arc<Thread>,
+ guard: &mut Guard<'_, ProcessInner, SpinLockBackend>,
+ deferred: &mut Option<Arc<Thread>>,
+ ) -> Self {
assert!(core::ptr::eq(&thread.process.inner, guard.lock_ref()));
// INVARIANT: We are pushing this thread to the right `ready_threads` list.
if let Ok(list_arc) = ListArc::try_from_arc(thread.clone()) {
+ if guard.has_deferred_timeout {
+ *deferred = guard.ready_threads.iter().next().map(Arc::from);
+ guard.has_deferred_timeout = false;
+ }
guard.ready_threads.push_front(list_arc);
} else {
// It is an error to hit this branch, and it should not be reachable. We try to do
@@ -1847,17 +1902,52 @@ fn new(thread: &'a Arc<Thread>, guard: &mut Guard<'_, ProcessInner, SpinLockBack
// question will sleep forever.
pr_err_ratelimited!("Same thread registered with `ready_threads` twice.\n");
}
- Self { thread }
+ Self {
+ thread,
+ unregistered: false,
+ }
+ }
+
+ pub(crate) fn maybe_unregister(
+ &mut self,
+ guard: &mut Guard<'_, ProcessInner, SpinLockBackend>,
+ ) -> bool {
+ assert!(core::ptr::eq(&self.thread.process.inner, guard.lock_ref()));
+ if self.unregistered {
+ return true;
+ }
+ // SAFETY: We asserted above that `guard` is the lock for `self.thread.process.inner`, and
+ // the thread has the invariant that we never push it to any other linked list than the
+ // `ready_threads` list of its parent process. Therefore, the thread is either in that
+ // list, or in no list.
+ let Some(list_arc) = (unsafe { guard.ready_threads.remove(self.thread) }) else {
+ self.unregistered = true;
+ return true;
+ };
+ if guard.ready_threads.is_empty() {
+ guard.ready_threads.push_front(list_arc);
+ guard.has_deferred_timeout = true;
+ return false;
+ }
+ self.unregistered = true;
+ true
}
}
impl Drop for Registration<'_> {
fn drop(&mut self) {
+ if self.unregistered {
+ return;
+ }
let mut inner = self.thread.process.inner.lock();
// SAFETY: The thread has the invariant that we never push it to any other linked list than
// the `ready_threads` list of its parent process. Therefore, the thread is either in that
// list, or in no list.
unsafe { inner.ready_threads.remove(self.thread) };
+ if inner.ready_threads.is_empty() {
+ inner.has_deferred_timeout = false;
+ }
+ self.unregistered = true;
}
}
@@ -1877,5 +1967,5 @@ fn drop(&mut self) {
pub(crate) enum GetWorkOrRegister<'a> {
Work(DLArc<dyn DeliverToRead>),
- Register(Registration<'a>),
+ Register(Registration<'a>, Delta),
}
diff --git a/drivers/android/binder/thread.rs b/drivers/android/binder/thread.rs
index 8efda6e9ded1..b6318b276b07 100644
--- a/drivers/android/binder/thread.rs
+++ b/drivers/android/binder/thread.rs
@@ -17,7 +17,7 @@
seq_file::SeqFile,
seq_print,
sync::atomic::{ordering::Relaxed, Atomic},
- sync::{aref::ARef, Arc, CondVar, SpinLock},
+ sync::{aref::ARef, Arc, CondVar, CondVarTimeoutResult, SpinLock},
task::Task,
uaccess::{UserPtr, UserSlice, UserSliceReader},
uapi,
@@ -252,6 +252,9 @@ struct InnerThread {
/// Determines whether the looper should return.
looper_need_return: bool,
+ /// Determines whether an expired idle timeout was deferred while sole ready thread.
+ deferred_timeout: bool,
+
/// Determines if thread is dead.
is_dead: bool,
@@ -289,6 +292,7 @@ pub enum LooperFlag {
Waiting = bit_u32(4),
WaitingProc = bit_u32(5),
Poll = bit_u32(6),
+ Started = bit_u32(7),
}
);
@@ -302,6 +306,7 @@ fn next_err_id() -> u32 {
Ok(Self {
looper_flags: LooperFlags::default(),
looper_need_return: false,
+ deferred_timeout: false,
is_dead: false,
process_work_list: false,
reply_work: ThreadError::try_new(pid)?,
@@ -400,7 +405,9 @@ fn looper_enter(&mut self) {
fn looper_register(&mut self, valid: bool) {
self.looper_flags |= LooperFlag::Registered;
- if !valid || self.looper_flags.contains(LooperFlag::Entered) {
+ if valid {
+ self.looper_flags |= LooperFlag::Started;
+ } else {
self.looper_flags |= LooperFlag::Invalid;
}
}
@@ -415,6 +422,19 @@ fn is_looper(&self) -> bool {
.contains_any(LooperFlag::Entered | LooperFlag::Registered)
}
+ fn is_registered_looper(&self) -> bool {
+ self.looper_flags.contains(LooperFlag::Registered)
+ && !self.looper_flags.contains(LooperFlag::Invalid)
+ }
+
+ /// Ensures we don't time out the main thread as this would lead to needless wakeups.
+ fn can_timeout(&self) -> bool {
+ self.is_registered_looper()
+ && !self
+ .looper_flags
+ .contains_any(LooperFlag::Entered | LooperFlag::Exited | LooperFlag::Poll)
+ }
+
/// Determines whether the thread should attempt to fetch work items from the process queue.
/// This is generally case when the thread is registered as a looper and not part of a
/// transaction stack. But if there is local work, we want to return to userspace before we
@@ -625,31 +645,76 @@ fn get_work(self: &Arc<Self>, wait: bool) -> Result<Option<DLArc<dyn DeliverToRe
}
// Get work from the process queue. If none is available, atomically register as ready.
- let reg = match self
+ let (mut reg, idle_timeout) = match self
.process
.get_work_or_register(self, thread_has_deferred_work)
{
GetWorkOrRegister::Work(work) => return Ok(Some(work)),
- GetWorkOrRegister::Register(reg) => reg,
+ GetWorkOrRegister::Register(reg, idle_timeout) => (reg, idle_timeout),
};
+ // Updated on spurious wakeup with remaining timeout.
+ let mut timeout = if idle_timeout.is_zero() {
+ 0
+ } else {
+ idle_timeout.to_jiffies_timeout().as_jiffies_unsigned() as kernel::time::Jiffies
+ };
let mut inner = self.inner.lock();
loop {
if let Some(work) = inner.pop_work() {
+ inner.looper_flags &= !(LooperFlag::Waiting | LooperFlag::WaitingProc);
return Ok(Some(work));
}
inner.looper_flags |= LooperFlag::Waiting | LooperFlag::WaitingProc;
- let signal_pending = self.work_condvar.wait_interruptible_freezable(&mut inner);
- inner.looper_flags &= !(LooperFlag::Waiting | LooperFlag::WaitingProc);
+ let timeout_result = if inner.can_timeout() && timeout != 0 {
+ self.work_condvar
+ .wait_interruptible_freezable_timeout(&mut inner, timeout)
+ } else {
+ let signal_pending = self.work_condvar.wait_interruptible_freezable(&mut inner);
+ if signal_pending {
+ CondVarTimeoutResult::Signal { jiffies: 0 }
+ } else {
+ CondVarTimeoutResult::Woken { jiffies: 0 }
+ }
+ };
+ let deferred_timeout = inner.deferred_timeout;
+ inner.deferred_timeout = false;
+
+ let signal_pending = matches!(timeout_result, CondVarTimeoutResult::Signal { .. });
+ let timed_out = matches!(timeout_result, CondVarTimeoutResult::Timeout)
+ || (deferred_timeout && !signal_pending);
+
+ if timed_out && !signal_pending && !inner.looper_need_return && !inner.process_work_list
+ {
+ drop(inner);
+ let mut inner_process = self.process.inner.lock();
+ inner = self.inner.lock();
+ if !inner.looper_need_return && inner_process.idle_timeout().is_zero() {
+ timeout = 0;
+ drop(inner_process);
+ continue;
+ }
+ if !inner.looper_need_return
+ && !inner.process_work_list
+ && !reg.maybe_unregister(&mut inner_process)
+ {
+ timeout = 0;
+ inner.deferred_timeout = true;
+ drop(inner_process);
+ continue;
+ }
+ drop(inner_process);
+ }
- if signal_pending || inner.looper_need_return {
+ if signal_pending || timed_out || inner.looper_need_return {
// We need to return now.
//
// We need to pull the thread off the list of ready threads (by dropping `reg`),
// then check the state again after it's off the list to ensure that something was
// not queued in the meantime. If something has been queued (or if there is
// deferred work), we just return it (instead of the error).
+ inner.looper_flags &= !(LooperFlag::Waiting | LooperFlag::WaitingProc);
drop(inner);
drop(reg);
@@ -658,13 +723,30 @@ fn get_work(self: &Arc<Self>, wait: bool) -> Result<Option<DLArc<dyn DeliverToRe
let res = match inner.pop_work() {
Some(work) => Ok(Some(work)),
None if signal_pending => Err(EINTR),
+ None if timed_out && !inner.looper_need_return => Err(ETIMEDOUT),
None => Ok(None),
};
return res;
}
+
+ // Update timeout on spurious wake.
+ if let CondVarTimeoutResult::Woken { jiffies } = timeout_result {
+ timeout = jiffies;
+ }
+ }
+ }
+
+ pub(crate) fn notify_if_deferred_timeout(&self) {
+ let should_notify = self.inner.lock().deferred_timeout;
+ if should_notify {
+ self.work_condvar.notify_one();
}
}
+ pub(crate) fn clear_deferred_timeout(&self) {
+ self.inner.lock().deferred_timeout = false;
+ }
+
/// Push the provided work item to be delivered to user space via this thread.
///
/// Returns whether the item was successfully pushed. This can only fail if the thread is dead.
@@ -1567,8 +1649,10 @@ fn write(self: &Arc<Self>, req: &mut BinderWriteRead) -> Result {
BC_CLEAR_DEATH_NOTIFICATION => self.process.clear_death(&mut reader, self)?,
BC_DEAD_BINDER_DONE => self.process.dead_binder_done(reader.read()?, self),
BC_REGISTER_LOOPER => {
- let valid = self.process.register_thread();
- self.inner.lock().looper_register(valid);
+ let mut inner_process = self.process.inner.lock();
+ let mut inner = self.inner.lock();
+ let valid = !inner.is_looper() && inner_process.register_thread();
+ inner.looper_register(valid);
}
BC_ENTER_LOOPER => self.inner.lock().looper_enter(),
BC_EXIT_LOOPER => self.inner.lock().looper_exit(),
@@ -1625,6 +1709,7 @@ fn read(self: &Arc<Self>, req: &mut BinderWriteRead, wait: bool) -> Result {
// Loop doing work while there is room in the buffer.
let initial_len = writer.len();
+ let mut timed_out = false;
while writer.len() >= size_of::<uapi::binder_transaction_data_secctx>() + 4 {
match getter(self, wait && initial_len == writer.len()) {
Ok(Some(work)) => match work.into_arc().do_work(self, &mut writer) {
@@ -1638,6 +1723,13 @@ fn read(self: &Arc<Self>, req: &mut BinderWriteRead, wait: bool) -> Result {
break;
}
Err(err) => {
+ // Timeout isn't an error for the caller so swallow it here and instead
+ // write BR_FINISHED.
+ if err == ETIMEDOUT {
+ timed_out = true;
+ writer.write_code(BR_FINISHED)?;
+ break;
+ }
// Propagate the error if we haven't written anything else.
if err != EINTR && err != EAGAIN {
pr_warn_ratelimited!("Failure in work getter: {:?}\n", err);
@@ -1654,7 +1746,7 @@ fn read(self: &Arc<Self>, req: &mut BinderWriteRead, wait: bool) -> Result {
req.read_consumed += read_len - writer.len() as u64;
// Write BR_SPAWN_LOOPER if the process needs more threads for its pool.
- if has_noop_placeholder && in_pool && self.process.needs_thread() {
+ if has_noop_placeholder && in_pool && !timed_out && self.process.needs_thread() {
let mut writer = UserSlice::new(
UserPtr::from_addr(req.read_buffer as usize),
req.read_size as usize,
@@ -1662,6 +1754,7 @@ fn read(self: &Arc<Self>, req: &mut BinderWriteRead, wait: bool) -> Result {
.writer();
writer.write(&BR_SPAWN_LOOPER)?;
}
+
Ok(())
}
@@ -1708,6 +1801,10 @@ pub(crate) fn write_read(self: &Arc<Self>, data: UserSlice, wait: bool) -> Resul
ret
}
+ pub(crate) fn is_started_looper(&self) -> bool {
+ self.inner.lock().looper_flags.contains(LooperFlag::Started)
+ }
+
pub(crate) fn poll(&self) -> Result<(bool, u32)> {
let mut inner = self.inner.lock();
Ok((inner.should_use_process_work_queue(), inner.poll()))
diff --git a/include/uapi/linux/android/binder.h b/include/uapi/linux/android/binder.h
index 96e5b0184a1b..c205cfb9a515 100644
--- a/include/uapi/linux/android/binder.h
+++ b/include/uapi/linux/android/binder.h
@@ -259,6 +259,14 @@ struct binder_extended_error {
enum {
BINDER_WRITE_READ = _IOWR('b', 1, struct binder_write_read),
+ /*
+ * Configure the per-process idle timeout in milliseconds for registered
+ * looper threads (BC_REGISTER_LOOPER). A value of 0 disables spin-down
+ * (default); negative values return -EINVAL. Very large values saturate
+ * to the kernel's maximum timeout. Non-zero updates apply to subsequent
+ * waits; resetting to 0 also cancels pending spin-down for waiting and
+ * deferred threads.
+ */
BINDER_SET_IDLE_TIMEOUT = _IOW('b', 3, __s64),
BINDER_SET_MAX_THREADS = _IOW('b', 5, __u32),
BINDER_SET_IDLE_PRIORITY = _IOW('b', 6, __s32),
@@ -438,8 +446,10 @@ enum binder_driver_return_protocol {
BR_FINISHED = _IO('r', 14),
/*
- * not currently supported
- * stop threadpool thread
+ * No parameters. The driver has determined that a registered looper
+ * thread has been idle past the timeout configured via
+ * BINDER_SET_IDLE_TIMEOUT and should exit its looper loop via
+ * BC_EXIT_LOOPER and BINDER_THREAD_EXIT.
*/
BR_DEAD_BINDER = _IOR('r', 15, binder_uintptr_t),
--
2.56.1.915.g69d5ec7298-goog
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH 3/4] selftests/binderfs: extract shared namespace and mount helpers
2026-12-04 0:32 [PATCH 0/4] rust_binder: add support for idle thread timeout Nicholas Giunta
2026-12-04 0:32 ` [PATCH 1/4] rust: sync: condvar: add wait_interruptible_freezable_timeout() Nicholas Giunta
2026-12-04 0:32 ` [PATCH 2/4] rust_binder: add support for thread timeout Nicholas Giunta
@ 2026-12-04 0:32 ` Nicholas Giunta
2026-12-04 0:32 ` [PATCH 4/4] selftests/binderfs: add idle timeout tests Nicholas Giunta
3 siblings, 0 replies; 5+ messages in thread
From: Nicholas Giunta @ 2026-12-04 0:32 UTC (permalink / raw)
To: Greg Kroah-Hartman, Carlos Llamas, Alice Ryhl,
Arve Hjønnevåg, Todd Kjos, Christian Brauner,
Boqun Feng, Gary Guo, Miguel Ojeda, Shuah Khan
Cc: Lyude Paul, Daniel Almeida, Onur Özkan,
Björn Roy Baron, Benno Lossin, Andreas Hindborg,
Trevor Gross, Danilo Krummrich, Tamir Duberstein,
Alexandre Courbot, linux-kernel, rust-for-linux, linux-kselftest,
linux-api, Nicholas Giunta
Extract the duplicated user-namespace entry, binderfs mount/unmount, and
binder-control device allocation logic into reusable helpers
(enter_userns(), binderfs_mount(), binderfs_umount(), and
binderfs_add_device()) and convert __do_binderfs_test(),
binderfs_stress, binderfs_test_privileged, and
binderfs_test_unprivileged to use them.
Since kselftest_harness already runs each TEST() in an isolated child
process, enter_userns() sets up single-ID uid/gid mappings in-process
without an extra fork()/socketpair() handshake. binderfs_mount() and
binderfs_umount() also ensure temporary mount directories are always
removed on both normal exit and ENODEV skip paths.
Also convert __do_binderfs_test() to return void and call SKIP() only on
-ENODEV, fixing a pre-existing issue where binderfs_test_privileged and
binderfs_test_unprivileged turned any non-ENODEV failure inside
__do_binderfs_test() into a SKIP.
This prepares binderfs_test.c for adding idle timeout selftests without
duplicating namespace and binderfs setup boilerplate.
Assisted-by: Gemini
Signed-off-by: Nicholas Giunta <grahalt@google.com>
---
.../selftests/filesystems/binderfs/binderfs_test.c | 395 ++++++++-------------
1 file changed, 144 insertions(+), 251 deletions(-)
diff --git a/tools/testing/selftests/filesystems/binderfs/binderfs_test.c b/tools/testing/selftests/filesystems/binderfs/binderfs_test.c
index cd82c89f558f..7059bc9d25bd 100644
--- a/tools/testing/selftests/filesystems/binderfs/binderfs_test.c
+++ b/tools/testing/selftests/filesystems/binderfs/binderfs_test.c
@@ -12,11 +12,9 @@
#include <sys/fsuid.h>
#include <sys/ioctl.h>
#include <sys/mount.h>
-#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/sysinfo.h>
#include <sys/types.h>
-#include <sys/wait.h>
#include <unistd.h>
#include <linux/android/binder.h>
#include <linux/android/binderfs.h>
@@ -53,13 +51,70 @@ static void change_mountns(struct __test_metadata *_metadata)
}
}
-static int __do_binderfs_test(struct __test_metadata *_metadata)
+static int binderfs_mount(char *mntpt, size_t len)
{
- int fd, ret, saved_errno, result = 1;
- size_t len;
+ int err;
+
+ if (len < sizeof(P_tmpdir "/binderfs_XXXXXX"))
+ return -EINVAL;
+ memcpy(mntpt, P_tmpdir "/binderfs_XXXXXX",
+ sizeof(P_tmpdir "/binderfs_XXXXXX"));
+ if (!mkdtemp(mntpt)) {
+ mntpt[0] = '\0';
+ return -errno;
+ }
+
+ if (mount(NULL, mntpt, "binder", 0, 0) < 0) {
+ err = errno;
+ rmdir(mntpt);
+ mntpt[0] = '\0';
+ return -err;
+ }
+
+ return 0;
+}
+
+static int binderfs_umount(char *mntpt)
+{
+ int ret = 0;
+
+ if (!mntpt[0])
+ return 0;
+ if (umount2(mntpt, MNT_DETACH) < 0)
+ ret = -errno;
+ if (rmdir(mntpt) < 0 && !ret)
+ ret = -errno;
+ mntpt[0] = '\0';
+ return ret;
+}
+
+static int binderfs_add_device(const char *mntpt, const char *name,
+ struct binderfs_device *dev_out)
+{
+ char ctl_path[sizeof(P_tmpdir "/binderfs_XXXXXX/") + BINDERFS_MAX_NAME];
+ struct binderfs_device dev = { 0 };
+ int fd, ret, err;
+
+ snprintf(ctl_path, sizeof(ctl_path), "%s/binder-control", mntpt);
+ fd = open(ctl_path, O_RDONLY | O_CLOEXEC);
+ if (fd < 0)
+ return -errno;
+
+ snprintf(dev.name, sizeof(dev.name), "%s", name);
+ ret = ioctl(fd, BINDER_CTL_ADD, &dev);
+ err = ret < 0 ? -errno : 0;
+ close(fd);
+ if (!err && dev_out)
+ *dev_out = dev;
+ return err;
+}
+
+static void __do_binderfs_test(struct __test_metadata *_metadata)
+{
+ int fd, ret, saved_errno;
struct binderfs_device device = { 0 };
struct binder_version version = { 0 };
- char binderfs_mntpt[] = P_tmpdir "/binderfs_XXXXXX",
+ char binderfs_mntpt[sizeof(P_tmpdir "/binderfs_XXXXXX")],
device_path[sizeof(P_tmpdir "/binderfs_XXXXXX/") + BINDERFS_MAX_NAME];
static const char * const binder_features[] = {
"oneway_spam_detection",
@@ -70,39 +125,19 @@ static int __do_binderfs_test(struct __test_metadata *_metadata)
change_mountns(_metadata);
- EXPECT_NE(mkdtemp(binderfs_mntpt), NULL) {
- TH_LOG("%s - Failed to create binderfs mountpoint",
- strerror(errno));
- goto out;
- }
-
- ret = mount(NULL, binderfs_mntpt, "binder", 0, 0);
- EXPECT_EQ(ret, 0) {
- if (errno == ENODEV)
- SKIP(goto out, "binderfs missing");
- TH_LOG("%s - Failed to mount binderfs", strerror(errno));
- goto rmdir;
+ ret = binderfs_mount(binderfs_mntpt, sizeof(binderfs_mntpt));
+ if (ret == -ENODEV)
+ SKIP(return, "The Android binderfs filesystem is not available");
+ ASSERT_EQ(ret, 0) {
+ TH_LOG("%s - Failed to mount binderfs", strerror(-ret));
}
/* success: binderfs mounted */
- memcpy(device.name, "my-binder", strlen("my-binder"));
-
- snprintf(device_path, sizeof(device_path), "%s/binder-control", binderfs_mntpt);
- fd = open(device_path, O_RDONLY | O_CLOEXEC);
- EXPECT_GE(fd, 0) {
- TH_LOG("%s - Failed to open binder-control device",
- strerror(errno));
- goto umount;
- }
-
- ret = ioctl(fd, BINDER_CTL_ADD, &device);
- saved_errno = errno;
- close(fd);
- errno = saved_errno;
- EXPECT_GE(ret, 0) {
+ ret = binderfs_add_device(binderfs_mntpt, "my-binder", &device);
+ EXPECT_EQ(ret, 0) {
TH_LOG("%s - Failed to allocate new binder device",
- strerror(errno));
+ strerror(-ret));
goto umount;
}
@@ -169,39 +204,12 @@ static int __do_binderfs_test(struct __test_metadata *_metadata)
}
/* success: binder feature files found */
- result = 0;
umount:
- ret = umount2(binderfs_mntpt, MNT_DETACH);
- EXPECT_EQ(ret, 0) {
- TH_LOG("%s - Failed to unmount binderfs", strerror(errno));
- }
-rmdir:
- ret = rmdir(binderfs_mntpt);
+ ret = binderfs_umount(binderfs_mntpt);
EXPECT_EQ(ret, 0) {
- TH_LOG("%s - Failed to rmdir binderfs mount", strerror(errno));
- }
-out:
- return result;
-}
-
-static int wait_for_pid(pid_t pid)
-{
- int status, ret;
-
-again:
- ret = waitpid(pid, &status, 0);
- if (ret == -1) {
- if (errno == EINTR)
- goto again;
-
- return -1;
+ TH_LOG("%s - Failed to unmount/rmdir binderfs", strerror(-ret));
}
-
- if (!WIFEXITED(status))
- return -1;
-
- return WEXITSTATUS(status);
}
static int setid_userns_root(void)
@@ -222,17 +230,6 @@ enum idmap_type {
GID_MAP,
};
-static ssize_t read_nointr(int fd, void *buf, size_t count)
-{
- ssize_t ret;
-again:
- ret = read(fd, buf, count);
- if (ret < 0 && errno == EINTR)
- goto again;
-
- return ret;
-}
-
static ssize_t write_nointr(int fd, const void *buf, size_t count)
{
ssize_t ret;
@@ -292,67 +289,27 @@ static int write_id_mapping(enum idmap_type type, pid_t pid, const char *buf,
return 0;
}
-static void change_userns(struct __test_metadata *_metadata, int syncfds[2])
-{
- int ret;
- char buf;
-
- close_prot_errno_disarm(syncfds[1]);
-
- ret = unshare(CLONE_NEWUSER);
- ASSERT_EQ(ret, 0) {
- TH_LOG("%s - Failed to unshare user namespace",
- strerror(errno));
- }
-
- ret = write_nointr(syncfds[0], "1", 1);
- ASSERT_EQ(ret, 1) {
- TH_LOG("write_nointr() failed");
- }
-
- ret = read_nointr(syncfds[0], &buf, 1);
- ASSERT_EQ(ret, 1) {
- TH_LOG("read_nointr() failed");
- }
-
- close_prot_errno_disarm(syncfds[0]);
-
- ASSERT_EQ(setid_userns_root(), 0) {
- TH_LOG("setid_userns_root() failed");
- }
-}
-
-static void change_idmaps(struct __test_metadata *_metadata, int syncfds[2], pid_t pid)
+static int enter_userns(void)
{
- int ret;
- char buf;
- char id_map[4096];
+ uid_t uid = getuid();
+ gid_t gid = getgid();
+ char id_map[64];
- close_prot_errno_disarm(syncfds[0]);
+ if (unshare(CLONE_NEWUSER) < 0)
+ return -errno;
- ret = read_nointr(syncfds[1], &buf, 1);
- ASSERT_EQ(ret, 1) {
- TH_LOG("read_nointr() failed");
- }
+ snprintf(id_map, sizeof(id_map), "0 %u 1\n", uid);
+ if (write_id_mapping(UID_MAP, getpid(), id_map, strlen(id_map)) < 0)
+ return errno ? -errno : -EIO;
- snprintf(id_map, sizeof(id_map), "0 %d 1\n", getuid());
- ret = write_id_mapping(UID_MAP, pid, id_map, strlen(id_map));
- ASSERT_EQ(ret, 0) {
- TH_LOG("write_id_mapping(UID_MAP) failed");
- }
+ snprintf(id_map, sizeof(id_map), "0 %u 1\n", gid);
+ if (write_id_mapping(GID_MAP, getpid(), id_map, strlen(id_map)) < 0)
+ return errno ? -errno : -EIO;
- snprintf(id_map, sizeof(id_map), "0 %d 1\n", getgid());
- ret = write_id_mapping(GID_MAP, pid, id_map, strlen(id_map));
- ASSERT_EQ(ret, 0) {
- TH_LOG("write_id_mapping(GID_MAP) failed");
- }
+ if (setid_userns_root() < 0)
+ return errno ? -errno : -EPERM;
- ret = write_nointr(syncfds[1], "1", 1);
- ASSERT_EQ(ret, 1) {
- TH_LOG("write_nointr() failed");
- }
-
- close_prot_errno_disarm(syncfds[1]);
+ return 0;
}
struct __test_metadata *_thread_metadata;
@@ -380,116 +337,79 @@ static void *binder_version_thread(void *data)
TEST(binderfs_stress)
{
int fds[1000];
- int syncfds[2];
- pid_t pid;
- int fd, ret;
- size_t len;
- struct binderfs_device device = { 0 };
- char binderfs_mntpt[] = P_tmpdir "/binderfs_XXXXXX",
+ int i, j, k, nthreads, ret;
+ pthread_attr_t attr;
+ pthread_t threads[DEFAULT_THREADS];
+ char binderfs_mntpt[sizeof(P_tmpdir "/binderfs_XXXXXX")],
device_path[sizeof(P_tmpdir "/binderfs_XXXXXX/") + BINDERFS_MAX_NAME];
- ret = socketpair(PF_LOCAL, SOCK_STREAM | SOCK_CLOEXEC, 0, syncfds);
+ ret = enter_userns();
ASSERT_EQ(ret, 0) {
- TH_LOG("%s - Failed to create socket pair", strerror(errno));
+ TH_LOG("%s - Failed to enter user namespace", strerror(-ret));
}
+ change_mountns(_metadata);
- pid = fork();
- ASSERT_GE(pid, 0) {
- TH_LOG("%s - Failed to fork", strerror(errno));
- close_prot_errno_disarm(syncfds[0]);
- close_prot_errno_disarm(syncfds[1]);
+ ret = binderfs_mount(binderfs_mntpt, sizeof(binderfs_mntpt));
+ ASSERT_EQ(ret, 0) {
+ TH_LOG("%s - Failed to mount binderfs (check CONFIG_ANDROID_BINDER_IPC_RUST)",
+ strerror(-ret));
}
- if (pid == 0) {
- int i, j, k, nthreads;
- pthread_attr_t attr;
- pthread_t threads[DEFAULT_THREADS];
- change_userns(_metadata, syncfds);
- change_mountns(_metadata);
+ for (i = 0; i < ARRAY_SIZE(fds); i++) {
+ char name[16];
- ASSERT_NE(mkdtemp(binderfs_mntpt), NULL) {
- TH_LOG("%s - Failed to create binderfs mountpoint",
- strerror(errno));
- }
-
- ret = mount(NULL, binderfs_mntpt, "binder", 0, 0);
+ snprintf(name, sizeof(name), "%d", i);
+ ret = binderfs_add_device(binderfs_mntpt, name, NULL);
ASSERT_EQ(ret, 0) {
- TH_LOG("%s - Failed to mount binderfs, check if CONFIG_ANDROID_BINDER_IPC_RUST is enabled in the running kernel",
- strerror(errno));
+ TH_LOG("%s - Failed to allocate new binder device",
+ strerror(-ret));
}
- for (int i = 0; i < ARRAY_SIZE(fds); i++) {
-
- snprintf(device_path, sizeof(device_path),
- "%s/binder-control", binderfs_mntpt);
- fd = open(device_path, O_RDONLY | O_CLOEXEC);
- ASSERT_GE(fd, 0) {
- TH_LOG("%s - Failed to open binder-control device",
- strerror(errno));
- }
-
- memset(&device, 0, sizeof(device));
- snprintf(device.name, sizeof(device.name), "%d", i);
- ret = ioctl(fd, BINDER_CTL_ADD, &device);
- close_prot_errno_disarm(fd);
- ASSERT_EQ(ret, 0) {
- TH_LOG("%s - Failed to allocate new binder device",
- strerror(errno));
- }
-
- snprintf(device_path, sizeof(device_path), "%s/%d",
- binderfs_mntpt, i);
- fds[i] = open(device_path, O_RDONLY | O_CLOEXEC);
- ASSERT_GE(fds[i], 0) {
- TH_LOG("%s - Failed to open binder device", strerror(errno));
- }
+ snprintf(device_path, sizeof(device_path), "%s/%s",
+ binderfs_mntpt, name);
+ fds[i] = open(device_path, O_RDONLY | O_CLOEXEC);
+ ASSERT_GE(fds[i], 0) {
+ TH_LOG("%s - Failed to open binder device",
+ strerror(errno));
}
+ }
- ret = umount2(binderfs_mntpt, MNT_DETACH);
- ASSERT_EQ(ret, 0) {
- TH_LOG("%s - Failed to unmount binderfs", strerror(errno));
- rmdir(binderfs_mntpt);
- }
-
- nthreads = get_nprocs_conf();
- if (nthreads > DEFAULT_THREADS)
- nthreads = DEFAULT_THREADS;
-
- _thread_metadata = _metadata;
- pthread_attr_init(&attr);
- for (k = 0; k < ARRAY_SIZE(fds); k++) {
- for (i = 0; i < nthreads; i++) {
- ret = pthread_create(&threads[i], &attr, binder_version_thread, INT_TO_PTR(fds[k]));
- if (ret) {
- TH_LOG("%s - Failed to create thread %d",
- strerror(errno), i);
- break;
- }
- }
-
- for (j = 0; j < i; j++) {
- void *fdptr = NULL;
-
- ret = pthread_join(threads[j], &fdptr);
- if (ret)
- TH_LOG("%s - Failed to join thread %d for fd %d",
- strerror(errno), j, PTR_TO_INT(fdptr));
+ ret = binderfs_umount(binderfs_mntpt);
+ ASSERT_EQ(ret, 0) {
+ TH_LOG("%s - Failed to unmount/rmdir binderfs", strerror(-ret));
+ }
+
+ nthreads = get_nprocs_conf();
+ if (nthreads > DEFAULT_THREADS)
+ nthreads = DEFAULT_THREADS;
+
+ _thread_metadata = _metadata;
+ pthread_attr_init(&attr);
+ for (k = 0; k < ARRAY_SIZE(fds); k++) {
+ for (i = 0; i < nthreads; i++) {
+ ret = pthread_create(&threads[i], &attr,
+ binder_version_thread,
+ INT_TO_PTR(fds[k]));
+ if (ret) {
+ TH_LOG("%s - Failed to create thread %d",
+ strerror(errno), i);
+ break;
}
}
- pthread_attr_destroy(&attr);
- for (k = 0; k < ARRAY_SIZE(fds); k++)
- close(fds[k]);
+ for (j = 0; j < i; j++) {
+ void *fdptr = NULL;
- exit(EXIT_SUCCESS);
+ ret = pthread_join(threads[j], &fdptr);
+ if (ret)
+ TH_LOG("%s - Failed to join thread %d for fd %d",
+ strerror(errno), j, PTR_TO_INT(fdptr));
+ }
}
+ pthread_attr_destroy(&attr);
- change_idmaps(_metadata, syncfds, pid);
-
- ret = wait_for_pid(pid);
- ASSERT_EQ(ret, 0) {
- TH_LOG("wait_for_pid() failed");
- }
+ for (k = 0; k < ARRAY_SIZE(fds); k++)
+ close(fds[k]);
}
TEST(binderfs_test_privileged)
@@ -497,45 +417,18 @@ TEST(binderfs_test_privileged)
if (geteuid() != 0)
SKIP(return, "Tests are not run as root. Skipping privileged tests");
- if (__do_binderfs_test(_metadata))
- SKIP(return, "The Android binderfs filesystem is not available");
+ __do_binderfs_test(_metadata);
}
TEST(binderfs_test_unprivileged)
{
- int ret;
- int syncfds[2];
- pid_t pid;
+ int ret = enter_userns();
- ret = socketpair(PF_LOCAL, SOCK_STREAM | SOCK_CLOEXEC, 0, syncfds);
ASSERT_EQ(ret, 0) {
- TH_LOG("%s - Failed to create socket pair", strerror(errno));
- }
-
- pid = fork();
- ASSERT_GE(pid, 0) {
- close_prot_errno_disarm(syncfds[0]);
- close_prot_errno_disarm(syncfds[1]);
- TH_LOG("%s - Failed to fork", strerror(errno));
- }
-
- if (pid == 0) {
- change_userns(_metadata, syncfds);
- if (__do_binderfs_test(_metadata))
- exit(2);
- exit(EXIT_SUCCESS);
+ TH_LOG("%s - Failed to enter user namespace", strerror(-ret));
}
- change_idmaps(_metadata, syncfds, pid);
-
- ret = wait_for_pid(pid);
- if (ret) {
- if (ret == 2)
- SKIP(return, "The Android binderfs filesystem is not available");
- ASSERT_EQ(ret, 0) {
- TH_LOG("wait_for_pid() failed");
- }
- }
+ __do_binderfs_test(_metadata);
}
TEST_HARNESS_MAIN
--
2.56.1.915.g69d5ec7298-goog
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH 4/4] selftests/binderfs: add idle timeout tests
2026-12-04 0:32 [PATCH 0/4] rust_binder: add support for idle thread timeout Nicholas Giunta
` (2 preceding siblings ...)
2026-12-04 0:32 ` [PATCH 3/4] selftests/binderfs: extract shared namespace and mount helpers Nicholas Giunta
@ 2026-12-04 0:32 ` Nicholas Giunta
3 siblings, 0 replies; 5+ messages in thread
From: Nicholas Giunta @ 2026-12-04 0:32 UTC (permalink / raw)
To: Greg Kroah-Hartman, Carlos Llamas, Alice Ryhl,
Arve Hjønnevåg, Todd Kjos, Christian Brauner,
Boqun Feng, Gary Guo, Miguel Ojeda, Shuah Khan
Cc: Lyude Paul, Daniel Almeida, Onur Özkan,
Björn Roy Baron, Benno Lossin, Andreas Hindborg,
Trevor Gross, Danilo Krummrich, Tamir Duberstein,
Alexandre Courbot, linux-kernel, rust-for-linux, linux-kselftest,
linux-api, Nicholas Giunta
Add kselftest coverage under FIXTURE(binderfs_idle) for Rust binder's
per-process idle thread timeout support (BINDER_SET_IDLE_TIMEOUT and
BR_FINISHED):
- ioctl_and_default_disabled: verify a fresh binder fd defaults to
timeout=0 (disabled), validate BINDER_SET_IDLE_TIMEOUT argument bounds
(-1 and INT64_MIN return EINVAL; INT64_MAX, 100, and 0 succeed), and
verify resetting 100 -> 0 disables spin-down at runtime.
- spindown_and_respawn: verify BC_ENTER_LOOPER threads remain immune
even with a peer in ready_threads, BC_REGISTER_LOOPER threads spin
down with BR_FINISHED (without BR_SPAWN_LOOPER), and BINDER_THREAD_EXIT
decrements started_thread_count so subsequent cycles spawn fresh
looper threads.
- sole_ready_thread: verify the last remaining thread in ready_threads
defers its idle timeout until a peer joins (then exits with
BR_FINISHED), delivers BR_TRANSACTION rather than BR_FINISHED when
woken by incoming work, and stays alive when BINDER_SET_IDLE_TIMEOUT(0)
disables spin-down before a peer joins.
Probe BINDER_SET_IDLE_TIMEOUT(0) on a throwaway fd during fixture setup
so the tests skip cleanly on kernels without idle timeout support.
Assisted-by: Gemini
Signed-off-by: Nicholas Giunta <grahalt@google.com>
---
.../selftests/filesystems/binderfs/binderfs_test.c | 487 +++++++++++++++++++++
1 file changed, 487 insertions(+)
diff --git a/tools/testing/selftests/filesystems/binderfs/binderfs_test.c b/tools/testing/selftests/filesystems/binderfs/binderfs_test.c
index 7059bc9d25bd..39510117e395 100644
--- a/tools/testing/selftests/filesystems/binderfs/binderfs_test.c
+++ b/tools/testing/selftests/filesystems/binderfs/binderfs_test.c
@@ -6,13 +6,16 @@
#include <pthread.h>
#include <sched.h>
#include <stdbool.h>
+#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/fsuid.h>
#include <sys/ioctl.h>
+#include <sys/mman.h>
#include <sys/mount.h>
#include <sys/stat.h>
+#include <sys/syscall.h>
#include <sys/sysinfo.h>
#include <sys/types.h>
#include <unistd.h>
@@ -431,4 +434,488 @@ TEST(binderfs_test_unprivileged)
__do_binderfs_test(_metadata);
}
+#define BINDER_MMAP_SIZE (128 * 1024)
+
+enum {
+ BR_SEEN_SPAWN = 1,
+ BR_SEEN_FINISHED = 2,
+ BR_SEEN_TXN = 4,
+ BR_SEEN_COMPLETE = 8,
+};
+
+struct looper_worker {
+ int fd;
+ __u32 cmd;
+ int tid;
+ int done;
+ int seen;
+};
+
+static int binder_wr(int fd, const void *wbuf, size_t wlen,
+ void *rbuf, size_t rlen)
+{
+ struct binder_write_read bwr = {
+ .write_buffer = (binder_uintptr_t)(uintptr_t)wbuf,
+ .write_size = wlen,
+ .read_buffer = (binder_uintptr_t)(uintptr_t)rbuf,
+ .read_size = rlen,
+ };
+ int ret;
+
+ do {
+ ret = ioctl(fd, BINDER_WRITE_READ, &bwr);
+ } while (ret < 0 && errno == EINTR);
+
+ return ret < 0 ? -1 : (int)bwr.read_consumed;
+}
+
+static int binder_parse_read(const __u8 *buf, int len,
+ binder_uintptr_t *txn_buf)
+{
+ size_t off = 0;
+ int seen = 0;
+
+ if (len < 0)
+ return -1;
+
+ while (off + sizeof(__u32) <= (size_t)len) {
+ __u32 cmd;
+
+ memcpy(&cmd, buf + off, sizeof(cmd));
+ off += sizeof(cmd);
+ if (cmd == BR_NOOP) {
+ continue;
+ } else if (cmd == BR_TRANSACTION_COMPLETE) {
+ seen |= BR_SEEN_COMPLETE;
+ } else if (cmd == BR_SPAWN_LOOPER) {
+ seen |= BR_SEEN_SPAWN;
+ } else if (cmd == BR_FINISHED) {
+ seen |= BR_SEEN_FINISHED;
+ } else if (cmd == BR_TRANSACTION) {
+ struct binder_transaction_data tr;
+
+ if (off + sizeof(tr) > (size_t)len)
+ return -1;
+ memcpy(&tr, buf + off, sizeof(tr));
+ off += sizeof(tr);
+ if (txn_buf)
+ *txn_buf = tr.data.ptr.buffer;
+ seen |= BR_SEEN_TXN;
+ } else {
+ return -1;
+ }
+ }
+
+ return off == (size_t)len ? seen : -1;
+}
+
+static int binder_free_buffer(int fd, binder_uintptr_t ptr)
+{
+ __u32 cmd = BC_FREE_BUFFER;
+ __u8 buf[sizeof(cmd) + sizeof(ptr)];
+
+ memcpy(buf, &cmd, sizeof(cmd));
+ memcpy(buf + sizeof(cmd), &ptr, sizeof(ptr));
+ return binder_wr(fd, buf, sizeof(buf), NULL, 0);
+}
+
+static int binder_send_oneway(int cfd)
+{
+ __u32 cmd = BC_TRANSACTION;
+ struct binder_transaction_data txn = { .flags = TF_ONE_WAY };
+ __u8 wbuf[sizeof(cmd) + sizeof(txn)], rbuf[128];
+ int n, seen;
+
+ memcpy(wbuf, &cmd, sizeof(cmd));
+ memcpy(wbuf + sizeof(cmd), &txn, sizeof(txn));
+ n = binder_wr(cfd, wbuf, sizeof(wbuf), rbuf, sizeof(rbuf));
+ seen = binder_parse_read(rbuf, n, NULL);
+ return (seen > 0 && (seen & BR_SEEN_COMPLETE)) ? 0 : -1;
+}
+
+static int binder_trigger_spawn(int sfd, int cfd)
+{
+ __u8 rbuf[512];
+ binder_uintptr_t txn_buf = 0;
+ int n, seen;
+
+ if (binder_send_oneway(cfd) < 0)
+ return -1;
+ n = binder_wr(sfd, NULL, 0, rbuf, sizeof(rbuf));
+ seen = binder_parse_read(rbuf, n, &txn_buf);
+ if (seen < 0 || !(seen & BR_SEEN_SPAWN))
+ return -1;
+ if ((seen & BR_SEEN_TXN) && binder_free_buffer(sfd, txn_buf) < 0)
+ return -1;
+ return 0;
+}
+
+static void *looper_worker_fn(void *arg)
+{
+ struct looper_worker *w = arg;
+ __u8 rbuf[512];
+ binder_uintptr_t txn_buf = 0;
+ __u32 exit_cmd = BC_EXIT_LOOPER;
+ __s32 zero = 0;
+ int n, seen;
+
+ __atomic_store_n(&w->tid, (int)syscall(SYS_gettid), __ATOMIC_RELEASE);
+ n = binder_wr(w->fd, &w->cmd, sizeof(w->cmd), rbuf, sizeof(rbuf));
+
+ seen = binder_parse_read(rbuf, n, &txn_buf);
+ if (seen > 0 && (seen & BR_SEEN_TXN) &&
+ binder_free_buffer(w->fd, txn_buf) < 0)
+ seen = -1;
+ if (binder_wr(w->fd, &exit_cmd, sizeof(exit_cmd), NULL, 0) < 0 ||
+ ioctl(w->fd, BINDER_THREAD_EXIT, &zero) < 0)
+ seen = -1;
+
+ w->seen = seen;
+ __atomic_store_n(&w->done, 1, __ATOMIC_RELEASE);
+ return NULL;
+}
+
+static int proc_read_file(const char *path, char *buf, size_t len)
+{
+ int pfd;
+ ssize_t n;
+
+ pfd = open(path, O_RDONLY | O_CLOEXEC);
+ if (pfd < 0)
+ return -1;
+ do {
+ n = read(pfd, buf, len - 1);
+ } while (n < 0 && errno == EINTR);
+ close(pfd);
+ if (n < 0)
+ return -1;
+ buf[n] = '\0';
+ return (int)n;
+}
+
+static int looper_start(pthread_t *thr, struct looper_worker *w,
+ int fd, __u32 cmd)
+{
+ char wpath[64], spath[64], buf[256], *p;
+ int i, tid, n;
+
+ memset(w, 0, sizeof(*w));
+ w->fd = fd;
+ w->cmd = cmd;
+ if (pthread_create(thr, NULL, looper_worker_fn, w) != 0)
+ return -1;
+
+ for (i = 0; i < 5000; i++) {
+ tid = __atomic_load_n(&w->tid, __ATOMIC_ACQUIRE);
+ if (tid || __atomic_load_n(&w->done, __ATOMIC_ACQUIRE))
+ break;
+ usleep(1000);
+ }
+ if (__atomic_load_n(&w->done, __ATOMIC_ACQUIRE))
+ return 0;
+ if (!tid)
+ return -1;
+
+ snprintf(wpath, sizeof(wpath), "/proc/self/task/%d/wchan", tid);
+ snprintf(spath, sizeof(spath), "/proc/self/task/%d/stat", tid);
+ for (i = 0; i < 5000; i++) {
+ if (__atomic_load_n(&w->done, __ATOMIC_ACQUIRE))
+ return 0;
+ n = proc_read_file(wpath, buf, sizeof(buf));
+ if (n > 0) {
+ if (strcmp(buf, "rust_binder_wait") == 0)
+ return 0;
+ if (strcmp(buf, "0") == 0 || strstr(buf, "futex")) {
+ usleep(1000);
+ continue;
+ }
+ }
+ n = proc_read_file(spath, buf, sizeof(buf));
+ if (n < 0)
+ return __atomic_load_n(&w->done, __ATOMIC_ACQUIRE) ? 0 : -1;
+ p = strrchr(buf, ')');
+ if (p && p[1] == ' ' && p[2] == 'S')
+ return 0;
+ usleep(1000);
+ }
+ return -1;
+}
+
+static int looper_join(pthread_t thr, struct looper_worker *w)
+{
+ int i;
+
+ for (i = 0; i < 5000; i++) {
+ if (__atomic_load_n(&w->done, __ATOMIC_ACQUIRE))
+ return pthread_join(thr, NULL);
+ usleep(1000);
+ }
+ return -1;
+}
+
+struct binderfs_idle_ctx {
+ char mntpt[sizeof(P_tmpdir "/binderfs_XXXXXX")];
+ int sfd;
+ int cfd;
+ void *smap;
+};
+
+FIXTURE(binderfs_idle) {
+ struct binderfs_idle_ctx ctx;
+};
+
+static void idle_cleanup(struct binderfs_idle_ctx *ctx)
+{
+ if (ctx->cfd >= 0) {
+ close(ctx->cfd);
+ ctx->cfd = -1;
+ }
+ if (ctx->smap && ctx->smap != MAP_FAILED) {
+ munmap(ctx->smap, BINDER_MMAP_SIZE);
+ ctx->smap = MAP_FAILED;
+ }
+ if (ctx->sfd >= 0) {
+ close(ctx->sfd);
+ ctx->sfd = -1;
+ }
+ binderfs_umount(ctx->mntpt);
+}
+
+FIXTURE_SETUP(binderfs_idle)
+{
+ char path[sizeof(self->ctx.mntpt) + 1 + BINDERFS_MAX_NAME];
+ __u32 max_threads = 1, enter = BC_ENTER_LOOPER;
+ __s64 probe_timeout = 0;
+ __s32 zero = 0;
+ int probe_fd, ret;
+
+ self->ctx.mntpt[0] = '\0';
+ self->ctx.sfd = -1;
+ self->ctx.cfd = -1;
+ self->ctx.smap = MAP_FAILED;
+
+ if (geteuid() != 0) {
+ ret = enter_userns();
+ if (ret < 0)
+ SKIP(return, "enter_userns() unsupported: %s",
+ strerror(-ret));
+ }
+
+ change_mountns(_metadata);
+
+ ret = binderfs_mount(self->ctx.mntpt, sizeof(self->ctx.mntpt));
+ if (ret == -ENODEV)
+ SKIP(return, "binderfs missing");
+ ASSERT_EQ(ret, 0);
+
+ ASSERT_EQ(binderfs_add_device(self->ctx.mntpt, "my-binder", NULL), 0) {
+ idle_cleanup(&self->ctx);
+ }
+
+ snprintf(path, sizeof(path), "%s/my-binder", self->ctx.mntpt);
+
+ /* Probe ioctl on a throwaway fd so sfd keeps its default timeout. */
+ probe_fd = open(path, O_RDWR | O_CLOEXEC);
+ ASSERT_GE(probe_fd, 0) {
+ idle_cleanup(&self->ctx);
+ }
+ ret = ioctl(probe_fd, BINDER_SET_IDLE_TIMEOUT, &probe_timeout);
+ if (ret < 0 && (errno == EINVAL || errno == ENOTTY)) {
+ close(probe_fd);
+ idle_cleanup(&self->ctx);
+ SKIP(return, "BINDER_SET_IDLE_TIMEOUT not supported");
+ }
+ close(probe_fd);
+ ASSERT_EQ(ret, 0) {
+ idle_cleanup(&self->ctx);
+ }
+
+ self->ctx.sfd = open(path, O_RDWR | O_CLOEXEC);
+ ASSERT_GE(self->ctx.sfd, 0) {
+ idle_cleanup(&self->ctx);
+ }
+ self->ctx.smap = mmap(NULL, BINDER_MMAP_SIZE, PROT_READ, MAP_PRIVATE,
+ self->ctx.sfd, 0);
+ ASSERT_NE(self->ctx.smap, MAP_FAILED) {
+ idle_cleanup(&self->ctx);
+ }
+ ASSERT_EQ(ioctl(self->ctx.sfd, BINDER_SET_MAX_THREADS, &max_threads), 0) {
+ idle_cleanup(&self->ctx);
+ }
+ ASSERT_EQ(ioctl(self->ctx.sfd, BINDER_SET_CONTEXT_MGR, &zero), 0) {
+ idle_cleanup(&self->ctx);
+ }
+ ASSERT_GE(binder_wr(self->ctx.sfd, &enter, sizeof(enter), NULL, 0), 0) {
+ idle_cleanup(&self->ctx);
+ }
+
+ self->ctx.cfd = open(path, O_RDWR | O_CLOEXEC);
+ ASSERT_GE(self->ctx.cfd, 0) {
+ idle_cleanup(&self->ctx);
+ }
+ ASSERT_EQ(binder_trigger_spawn(self->ctx.sfd, self->ctx.cfd), 0) {
+ idle_cleanup(&self->ctx);
+ }
+}
+
+FIXTURE_TEARDOWN(binderfs_idle)
+{
+ idle_cleanup(&self->ctx);
+}
+
+static void assert_no_spindown(struct __test_metadata *_metadata,
+ int sfd, int cfd, useconds_t wait_us,
+ bool *spawned)
+{
+ struct looper_worker w_reg, w_enter;
+ pthread_t t_reg, t_enter;
+
+ ASSERT_EQ(looper_start(&t_reg, &w_reg, sfd, BC_REGISTER_LOOPER), 0);
+ ASSERT_EQ(looper_start(&t_enter, &w_enter, sfd, BC_ENTER_LOOPER), 0);
+
+ usleep(wait_us);
+ EXPECT_FALSE(__atomic_load_n(&w_reg.done, __ATOMIC_ACQUIRE));
+ EXPECT_FALSE(__atomic_load_n(&w_enter.done, __ATOMIC_ACQUIRE));
+
+ ASSERT_EQ(binder_send_oneway(cfd), 0);
+ ASSERT_EQ(binder_send_oneway(cfd), 0);
+ ASSERT_EQ(looper_join(t_reg, &w_reg), 0);
+ ASSERT_EQ(looper_join(t_enter, &w_enter), 0);
+
+ EXPECT_GT(w_reg.seen, 0);
+ EXPECT_EQ(w_reg.seen & (BR_SEEN_TXN | BR_SEEN_FINISHED), BR_SEEN_TXN);
+ EXPECT_GT(w_enter.seen, 0);
+ EXPECT_EQ(w_enter.seen & (BR_SEEN_TXN | BR_SEEN_FINISHED), BR_SEEN_TXN);
+
+ if (spawned)
+ *spawned = (w_reg.seen > 0 && (w_reg.seen & BR_SEEN_SPAWN)) ||
+ (w_enter.seen > 0 && (w_enter.seen & BR_SEEN_SPAWN));
+}
+
+TEST_F(binderfs_idle, ioctl_and_default_disabled)
+{
+ bool spawned = false;
+ __s64 timeout;
+
+ /* Default timeout is disabled (0); verify idle threads stay parked. */
+ assert_no_spindown(_metadata, self->ctx.sfd, self->ctx.cfd, 600 * 1000,
+ &spawned);
+
+ timeout = -1;
+ EXPECT_EQ(ioctl(self->ctx.sfd, BINDER_SET_IDLE_TIMEOUT, &timeout), -1);
+ EXPECT_EQ(errno, EINVAL);
+
+ timeout = INT64_MIN;
+ EXPECT_EQ(ioctl(self->ctx.sfd, BINDER_SET_IDLE_TIMEOUT, &timeout), -1);
+ EXPECT_EQ(errno, EINVAL);
+
+ timeout = INT64_MAX;
+ EXPECT_EQ(ioctl(self->ctx.sfd, BINDER_SET_IDLE_TIMEOUT, &timeout), 0);
+
+ timeout = 100;
+ ASSERT_EQ(ioctl(self->ctx.sfd, BINDER_SET_IDLE_TIMEOUT, &timeout), 0);
+
+ /* Resetting 100 -> 0 must disable spin-down at runtime. */
+ timeout = 0;
+ ASSERT_EQ(ioctl(self->ctx.sfd, BINDER_SET_IDLE_TIMEOUT, &timeout), 0);
+ if (!spawned)
+ ASSERT_EQ(binder_trigger_spawn(self->ctx.sfd, self->ctx.cfd), 0);
+ assert_no_spindown(_metadata, self->ctx.sfd, self->ctx.cfd, 250 * 1000,
+ NULL);
+}
+
+TEST_F(binderfs_idle, spindown_and_respawn)
+{
+ __s64 timeout = 100;
+ int cycle;
+
+ ASSERT_EQ(ioctl(self->ctx.sfd, BINDER_SET_IDLE_TIMEOUT, &timeout), 0);
+
+ /*
+ * Two cycles with max_threads=1 prove:
+ * 1. BC_ENTER_LOOPER is immune even with a peer (lead-wait on cycle 0
+ * would trigger deferred timeout + BR_FINISHED on w_reg arrival if
+ * Entered could time out).
+ * 2. BC_REGISTER_LOOPER exits with BR_FINISHED (no BR_SPAWN_LOOPER).
+ * 3. BINDER_THREAD_EXIT decrements started_thread_count so waking
+ * w_enter emits a fresh BR_SPAWN_LOOPER for the next cycle.
+ */
+ for (cycle = 0; cycle < 2; cycle++) {
+ struct looper_worker w_enter, w_reg;
+ pthread_t t_enter, t_reg;
+
+ ASSERT_EQ(looper_start(&t_enter, &w_enter, self->ctx.sfd,
+ BC_ENTER_LOOPER), 0);
+ if (cycle == 0)
+ usleep(200 * 1000);
+ ASSERT_EQ(looper_start(&t_reg, &w_reg, self->ctx.sfd,
+ BC_REGISTER_LOOPER), 0);
+
+ ASSERT_EQ(looper_join(t_reg, &w_reg), 0);
+ EXPECT_EQ(w_reg.seen, BR_SEEN_FINISHED);
+ EXPECT_FALSE(__atomic_load_n(&w_enter.done, __ATOMIC_ACQUIRE));
+
+ ASSERT_EQ(binder_send_oneway(self->ctx.cfd), 0);
+ ASSERT_EQ(looper_join(t_enter, &w_enter), 0);
+ EXPECT_EQ(w_enter.seen, BR_SEEN_TXN | BR_SEEN_SPAWN);
+ }
+}
+
+TEST_F(binderfs_idle, sole_ready_thread)
+{
+ struct looper_worker w_reg, w_enter;
+ pthread_t t_reg, t_enter;
+ __s64 timeout = 100;
+
+ ASSERT_EQ(ioctl(self->ctx.sfd, BINDER_SET_IDLE_TIMEOUT, &timeout), 0);
+
+ /* Sole ready thread defers timeout, then exits once a peer joins. */
+ ASSERT_EQ(looper_start(&t_reg, &w_reg, self->ctx.sfd,
+ BC_REGISTER_LOOPER), 0);
+ usleep(250 * 1000);
+ EXPECT_FALSE(__atomic_load_n(&w_reg.done, __ATOMIC_ACQUIRE));
+
+ ASSERT_EQ(looper_start(&t_enter, &w_enter, self->ctx.sfd,
+ BC_ENTER_LOOPER), 0);
+ ASSERT_EQ(looper_join(t_reg, &w_reg), 0);
+ EXPECT_EQ(w_reg.seen, BR_SEEN_FINISHED);
+
+ ASSERT_EQ(binder_send_oneway(self->ctx.cfd), 0);
+ ASSERT_EQ(looper_join(t_enter, &w_enter), 0);
+ EXPECT_EQ(w_enter.seen, BR_SEEN_TXN | BR_SEEN_SPAWN);
+
+ /* Deferred timeout woken by work delivers BR_TRANSACTION, not BR_FINISHED. */
+ ASSERT_EQ(looper_start(&t_reg, &w_reg, self->ctx.sfd,
+ BC_REGISTER_LOOPER), 0);
+ usleep(250 * 1000);
+ EXPECT_FALSE(__atomic_load_n(&w_reg.done, __ATOMIC_ACQUIRE));
+
+ ASSERT_EQ(binder_send_oneway(self->ctx.cfd), 0);
+ ASSERT_EQ(looper_join(t_reg, &w_reg), 0);
+ EXPECT_EQ(w_reg.seen, BR_SEEN_TXN);
+
+ /* Disabling timeout while deferred prevents BR_FINISHED when a peer joins. */
+ ASSERT_EQ(binder_trigger_spawn(self->ctx.sfd, self->ctx.cfd), 0);
+ ASSERT_EQ(looper_start(&t_reg, &w_reg, self->ctx.sfd,
+ BC_REGISTER_LOOPER), 0);
+ usleep(250 * 1000);
+ EXPECT_FALSE(__atomic_load_n(&w_reg.done, __ATOMIC_ACQUIRE));
+
+ timeout = 0;
+ ASSERT_EQ(ioctl(self->ctx.sfd, BINDER_SET_IDLE_TIMEOUT, &timeout), 0);
+ ASSERT_EQ(looper_start(&t_enter, &w_enter, self->ctx.sfd,
+ BC_ENTER_LOOPER), 0);
+ usleep(150 * 1000);
+ EXPECT_FALSE(__atomic_load_n(&w_reg.done, __ATOMIC_ACQUIRE));
+
+ ASSERT_EQ(binder_send_oneway(self->ctx.cfd), 0);
+ ASSERT_EQ(binder_send_oneway(self->ctx.cfd), 0);
+ ASSERT_EQ(looper_join(t_reg, &w_reg), 0);
+ ASSERT_EQ(looper_join(t_enter, &w_enter), 0);
+ EXPECT_GT(w_reg.seen, 0);
+ EXPECT_EQ(w_reg.seen & (BR_SEEN_TXN | BR_SEEN_FINISHED), BR_SEEN_TXN);
+ EXPECT_GT(w_enter.seen, 0);
+ EXPECT_EQ(w_enter.seen & (BR_SEEN_TXN | BR_SEEN_FINISHED), BR_SEEN_TXN);
+}
+
TEST_HARNESS_MAIN
--
2.56.1.915.g69d5ec7298-goog
^ permalink raw reply [flat|nested] 5+ messages in thread