[RFC 08/10] Set PF_RECLAIMABLE_STACK in various places

Alice Ryhl aliceryhl at google.com
Tue Sep 1 02:27:31 PDT 2026


On Thu, Aug 27, 2026 at 04:29:46PM -0700, David Stevens wrote:
> Annotate various blocking locations with the PF_RECLAIMABLE_STACK.
> 
> Signed-off-by: David Stevens <stevensd at google.com>
> ---
>  drivers/android/binder/thread.rs | 14 +++++++++++++
>  fs/eventpoll.c                   |  3 +++
>  fs/pipe.c                        | 28 ++++++++++++++++---------
>  fs/select.c                      |  3 +++
>  kernel/futex/waitwake.c          |  3 +++
>  kernel/signal.c                  | 36 +++++++++++++++++++-------------
>  kernel/time/hrtimer.c            |  3 +++
>  rust/kernel/task.rs              | 16 ++++++++++++++
>  8 files changed, 82 insertions(+), 24 deletions(-)
> 
> diff --git a/drivers/android/binder/thread.rs b/drivers/android/binder/thread.rs
> index bc0ef8927905..be62f7fd43ca 100644
> --- a/drivers/android/binder/thread.rs
> +++ b/drivers/android/binder/thread.rs
> @@ -538,13 +538,21 @@ fn get_work_local(self: &Arc<Self>, wait: bool) -> Result<Option<DLArc<dyn Deliv
>  
>          // Loop waiting only on the local queue (i.e., not registering with the process queue).
>          let mut inner = self.inner.lock();
> +        // SAFETY: Only accessed locally in this function
> +        let current = unsafe { Task::current() };

You can invoke kernel::current!() instead to avoid unsafe here.

>          loop {
>              if let Some(work) = inner.pop_work() {
>                  return Ok(Some(work));
>              }
>  
>              inner.looper_flags |= LOOPER_WAITING;
> +
> +            current.set_flag_bits(bindings::PF_RECLAIMABLE_STACK);
> +
>              let signal_pending = self.work_condvar.wait_interruptible_freezable(&mut inner);
> +
> +            current.clear_flag_bits(bindings::PF_RECLAIMABLE_STACK);

It would be nicer to define a guard type like you did in C so that this
is less "manual".

> diff --git a/rust/kernel/task.rs b/rust/kernel/task.rs
> index 38273f4eedb5..6168f058343a 100644
> --- a/rust/kernel/task.rs
> +++ b/rust/kernel/task.rs
> @@ -344,6 +344,22 @@ pub fn group_leader(&self) -> &Task {
>          // only be used while `current` is still valid, thus still running.
>          unsafe { &*ptr.cast() }
>      }
> +
> +    /// Sets the given task flag bits on the current task.
> +    #[inline]
> +    pub fn set_flag_bits(&self, set: u32) {
> +            // SAFETY: The `flags` field of `current` is not modified from other threads, so
> +	    // the non-atomic update isn't a race.
> +	    unsafe { (*self.as_ptr()).flags |= set }
> +    }
> +
> +    /// Clears the given task flag bits on the current task.
> +    #[inline]
> +    pub fn clear_flag_bits(&self, clear: u32) {
> +            // SAFETY: The `flags` field of `current` is not modified from other threads, so
> +	    // the non-atomic update isn't a race.
> +	    unsafe { (*self.as_ptr()).flags &= !clear }
> +    }

It looks like the indentation here is a bit off. Please try invoking
'make rustfmt' to reformat this code.

Alice



More information about the linux-arm-kernel mailing list