[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <c4e66f5a-a48c-5a72-a733-9e1bcd77274a@redhat.com>
Date: Thu, 3 Dec 2020 20:58:33 -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 1/3] rwsem: Implement down_read_killable_nested
On 12/3/20 3:10 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_killable_nested. This is needed so that kcmp_lock
> can be converted from working on a mutexes to working on rw_semaphores.
>
> 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 | 2 ++
> kernel/locking/rwsem.c | 14 ++++++++++++++
> 2 files changed, 16 insertions(+)
>
> diff --git a/include/linux/rwsem.h b/include/linux/rwsem.h
> index 25e3fde85617..13021b08b2ed 100644
> --- a/include/linux/rwsem.h
> +++ b/include/linux/rwsem.h
> @@ -171,6 +171,7 @@ extern void downgrade_write(struct rw_semaphore *sem);
> * See Documentation/locking/lockdep-design.rst for more details.)
> */
> extern void down_read_nested(struct rw_semaphore *sem, int subclass);
> +extern int __must_check down_read_killable_nested(struct rw_semaphore *sem, int subclass);
> extern void down_write_nested(struct rw_semaphore *sem, int subclass);
> extern int down_write_killable_nested(struct rw_semaphore *sem, int subclass);
> extern void _down_write_nest_lock(struct rw_semaphore *sem, struct lockdep_map *nest_lock);
> @@ -191,6 +192,7 @@ extern void down_read_non_owner(struct rw_semaphore *sem);
> extern void up_read_non_owner(struct rw_semaphore *sem);
> #else
> # define down_read_nested(sem, subclass) down_read(sem)
> +# define down_read_killable_nested(sem, subclass) down_read_killable(sem)
> # define down_write_nest_lock(sem, nest_lock) down_write(sem)
> # define down_write_nested(sem, subclass) down_write(sem)
> # define down_write_killable_nested(sem, subclass) down_write_killable(sem)
> diff --git a/kernel/locking/rwsem.c b/kernel/locking/rwsem.c
> index f11b9bd3431d..54d11cb97551 100644
> --- a/kernel/locking/rwsem.c
> +++ b/kernel/locking/rwsem.c
> @@ -1605,6 +1605,20 @@ void down_read_nested(struct rw_semaphore *sem, int subclass)
> }
> EXPORT_SYMBOL(down_read_nested);
>
> +int down_read_killable_nested(struct rw_semaphore *sem, int subclass)
> +{
> + might_sleep();
> + rwsem_acquire_read(&sem->dep_map, subclass, 0, _RET_IP_);
> +
> + if (LOCK_CONTENDED_RETURN(sem, __down_read_trylock, __down_read_killable)) {
> + rwsem_release(&sem->dep_map, _RET_IP_);
> + return -EINTR;
> + }
> +
> + return 0;
> +}
> +EXPORT_SYMBOL(down_read_killable_nested);
> +
> void _down_write_nest_lock(struct rw_semaphore *sem, struct lockdep_map *nest)
> {
> might_sleep();
Acked-by: Waiman Long <longman@...hat.com>
-Longman
Powered by blists - more mailing lists