lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Fri, 15 Oct 2021 12:13:59 +0200
From:   Peter Zijlstra <peterz@...radead.org>
To:     Yanfei Xu <yanfei.xu@...driver.com>
Cc:     mingo@...hat.com, will@...nel.org, longman@...hat.com,
        boqun.feng@...il.com, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2 2/3] locking/rwsem: disable preemption for spinning
 region

On Wed, Oct 13, 2021 at 09:41:53PM +0800, Yanfei Xu wrote:
> The spinning region rwsem_spin_on_owner() should not be preempted,
> however the rwsem_down_write_slowpath() invokes it and don't disable
> preemption. Fix it by adding a pair of preempt_disable/enable().

I'm thinking we should do this patch before #1, otherwise we have a
single patch window where we'll trigger the assertion, no?

> 
> Signed-off-by: Yanfei Xu <yanfei.xu@...driver.com>
> ---
>  kernel/locking/rwsem.c | 11 ++++++++---
>  1 file changed, 8 insertions(+), 3 deletions(-)
> 
> diff --git a/kernel/locking/rwsem.c b/kernel/locking/rwsem.c
> index 7b5af452ace2..06925b43c3e7 100644
> --- a/kernel/locking/rwsem.c
> +++ b/kernel/locking/rwsem.c
> @@ -1024,6 +1024,7 @@ rwsem_down_write_slowpath(struct rw_semaphore *sem, int state)
>  	enum writer_wait_state wstate;
>  	struct rwsem_waiter waiter;
>  	struct rw_semaphore *ret = sem;
> +	enum owner_state owner_state;
>  	DEFINE_WAKE_Q(wake_q);
>  
>  	/* do optimistic spinning and steal lock if possible */
> @@ -1099,9 +1100,13 @@ rwsem_down_write_slowpath(struct rw_semaphore *sem, int state)
>  		 * In this case, we attempt to acquire the lock again
>  		 * without sleeping.
>  		 */
> -		if (wstate == WRITER_HANDOFF &&
> -		    rwsem_spin_on_owner(sem) == OWNER_NULL)
> -			goto trylock_again;
> +		if (wstate == WRITER_HANDOFF) {
> +			preempt_disable();
> +			owner_state = rwsem_spin_on_owner(sem);
> +			preempt_enable();
> +			if (owner_state == OWNER_NULL)
> +				goto trylock_again;
> +		}
>  
>  		/* Block until there are no active lockers. */
>  		for (;;) {
> -- 
> 2.27.0
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ