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]
Message-ID: <620f0908-c70a-9e54-e1b5-71d086b20756@redhat.com>
Date:   Thu, 3 Dec 2020 20:59:13 -0500
From:   Waiman Long <longman@...hat.com>
To:     "Eric W. Biederman" <ebiederm@...ssion.com>,
        linux-kernel@...r.kernel.org
Cc:     Linus Torvalds <torvalds@...ux-foundation.org>,
        Peter Zijlstra <peterz@...radead.org>,
        Ingo Molnar <mingo@...hat.com>, Will Deacon <will@...nel.org>,
        Jann Horn <jannh@...gle.com>,
        Vasiliy Kulikov <segoon@...nwall.com>,
        Al Viro <viro@...iv.linux.org.uk>,
        Bernd Edlinger <bernd.edlinger@...mail.de>,
        Oleg Nesterov <oleg@...hat.com>,
        Christopher Yeoh <cyeoh@....ibm.com>,
        Cyrill Gorcunov <gorcunov@...il.com>,
        Sargun Dhillon <sargun@...gun.me>,
        Christian Brauner <christian.brauner@...ntu.com>,
        Arnd Bergmann <arnd@...db.de>,
        Arnaldo Carvalho de Melo <acme@...nel.org>
Subject: Re: [PATCH 2/3] rwsem: Implement down_read_interruptible

On 12/3/20 3:11 PM, Eric W. Biederman wrote:
> In preparation for converting exec_update_mutex to a rwsem so that
> multiple readers can execute in parallel and not deadlock, add
> down_read_interruptible.  This is needed for perf_event_open to be
> converted (with no semantic changes) from working on a mutex to
> wroking on a rwsem.
>
> Cc: Peter Zijlstra <peterz@...radead.org>
> Cc: Ingo Molnar <mingo@...hat.com>
> Cc: Will Deacon <will@...nel.org>
> Signed-off-by: Eric W. Biederman <ebiederm@...ssion.com>
> ---
>   include/linux/rwsem.h  |  1 +
>   kernel/locking/rwsem.c | 26 ++++++++++++++++++++++++++
>   2 files changed, 27 insertions(+)
>
> diff --git a/include/linux/rwsem.h b/include/linux/rwsem.h
> index 13021b08b2ed..4c715be48717 100644
> --- a/include/linux/rwsem.h
> +++ b/include/linux/rwsem.h
> @@ -123,6 +123,7 @@ static inline int rwsem_is_contended(struct rw_semaphore *sem)
>    * lock for reading
>    */
>   extern void down_read(struct rw_semaphore *sem);
> +extern int __must_check down_read_interruptible(struct rw_semaphore *sem);
>   extern int __must_check down_read_killable(struct rw_semaphore *sem);
>   
>   /*
> diff --git a/kernel/locking/rwsem.c b/kernel/locking/rwsem.c
> index 54d11cb97551..a163542d178e 100644
> --- a/kernel/locking/rwsem.c
> +++ b/kernel/locking/rwsem.c
> @@ -1345,6 +1345,18 @@ static inline void __down_read(struct rw_semaphore *sem)
>   	}
>   }
>   
> +static inline int __down_read_interruptible(struct rw_semaphore *sem)
> +{
> +	if (!rwsem_read_trylock(sem)) {
> +		if (IS_ERR(rwsem_down_read_slowpath(sem, TASK_INTERRUPTIBLE)))
> +			return -EINTR;
> +		DEBUG_RWSEMS_WARN_ON(!is_rwsem_reader_owned(sem), sem);
> +	} else {
> +		rwsem_set_reader_owned(sem);
> +	}
> +	return 0;
> +}
> +
>   static inline int __down_read_killable(struct rw_semaphore *sem)
>   {
>   	if (!rwsem_read_trylock(sem)) {
> @@ -1495,6 +1507,20 @@ void __sched down_read(struct rw_semaphore *sem)
>   }
>   EXPORT_SYMBOL(down_read);
>   
> +int __sched down_read_interruptible(struct rw_semaphore *sem)
> +{
> +	might_sleep();
> +	rwsem_acquire_read(&sem->dep_map, 0, 0, _RET_IP_);
> +
> +	if (LOCK_CONTENDED_RETURN(sem, __down_read_trylock, __down_read_interruptible)) {
> +		rwsem_release(&sem->dep_map, _RET_IP_);
> +		return -EINTR;
> +	}
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL(down_read_interruptible);
> +
>   int __sched down_read_killable(struct rw_semaphore *sem)
>   {
>   	might_sleep();

Acked-by: Waiman Long <longman@...hat.com>

-Longman

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ