Re: [RFC PATCH 1/4] locking/percpu-rwsem: add freezable alternative to down_read

From: James Bottomley
Date: Mon Mar 31 2025 - 15:51:57 EST


On Thu, 2025-03-27 at 10:06 -0400, James Bottomley wrote:
[...]
> -static void percpu_rwsem_wait(struct percpu_rw_semaphore *sem, bool
> reader)
> +static void percpu_rwsem_wait(struct percpu_rw_semaphore *sem, bool
> reader,
> +       bool freeze)
>  {
>   DEFINE_WAIT_FUNC(wq_entry, percpu_rwsem_wake_function);
>   bool wait;
> @@ -156,7 +157,8 @@ static void percpu_rwsem_wait(struct
> percpu_rw_semaphore *sem, bool reader)
>   spin_unlock_irq(&sem->waiters.lock);
>  
>   while (wait) {
> - set_current_state(TASK_UNINTERRUPTIBLE);
> + set_current_state(TASK_UNINTERRUPTIBLE |
> +   freeze ? TASK_FREEZABLE : 0);

This is a bit embarrassing, the bug I've been chasing is here: the ?
operator is lower in precedence than | meaning this expression always
evaluates to TASK_FREEZABLE and nothing else (which is why the process
goes into R state and never wakes up).

Let me fix that and redo all the testing.

Regards,

James