Message ID | 20210308205456.1317366-2-zackr@vmware.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | locking/rwsem: Add down_write_interruptible and use it | expand |
On Mon, Mar 08, 2021 at 03:54:55PM -0500, Zack Rusin wrote: > Add an interruptible version of down_write. It's the other > side of the already implemented down_read_interruptible. > It allows drivers which used custom locking code to > support interruptible rw semaphores to switch over > to rwsem. > > Cc: Peter Zijlstra <peterz@infradead.org> > Cc: Ingo Molnar <mingo@redhat.com> > Cc: Will Deacon <will@kernel.org> > Cc: linux-kernel@vger.kernel.org > Cc: dri-devel@lists.freedesktop.org No SoB! Assuning you actually wrote and and simply forgot to add it, the patch does look ok, so: Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
On 3/9/21 3:49 AM, Peter Zijlstra wrote: > On Mon, Mar 08, 2021 at 03:54:55PM -0500, Zack Rusin wrote: >> Add an interruptible version of down_write. It's the other >> side of the already implemented down_read_interruptible. >> It allows drivers which used custom locking code to >> support interruptible rw semaphores to switch over >> to rwsem. >> >> Cc: Peter Zijlstra <peterz@infradead.org> >> Cc: Ingo Molnar <mingo@redhat.com> >> Cc: Will Deacon <will@kernel.org> >> Cc: linux-kernel@vger.kernel.org >> Cc: dri-devel@lists.freedesktop.org > > No SoB! Ah, sorry, fixed that locally. > Assuning you actually wrote and and simply forgot to add it, the patch > does look ok, so: > > Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org> Thank you. I didn't want to bother you with the code in vmwgfx, so I only sent it to the lists (it was missing SoB as well): https://lore.kernel.org/patchwork/patch/1391810/ z
diff --git a/include/linux/rwsem.h b/include/linux/rwsem.h index 4c715be48717..753ae2cb8677 100644 --- a/include/linux/rwsem.h +++ b/include/linux/rwsem.h @@ -135,6 +135,7 @@ extern int down_read_trylock(struct rw_semaphore *sem); * lock for writing */ extern void down_write(struct rw_semaphore *sem); +extern int __must_check down_write_interruptible(struct rw_semaphore *sem); extern int __must_check down_write_killable(struct rw_semaphore *sem); /* diff --git a/kernel/locking/rwsem.c b/kernel/locking/rwsem.c index abba5df50006..0eadd20347de 100644 --- a/kernel/locking/rwsem.c +++ b/kernel/locking/rwsem.c @@ -1270,6 +1270,11 @@ static inline void __down_write(struct rw_semaphore *sem) __down_write_common(sem, TASK_UNINTERRUPTIBLE); } +static inline int __down_write_interruptible(struct rw_semaphore *sem) +{ + return __down_write_common(sem, TASK_INTERRUPTIBLE); +} + static inline int __down_write_killable(struct rw_semaphore *sem) { return __down_write_common(sem, TASK_KILLABLE); @@ -1408,6 +1413,24 @@ void __sched down_write(struct rw_semaphore *sem) } EXPORT_SYMBOL(down_write); +/* + * interruptible lock for writing + */ +int __sched down_write_interruptible(struct rw_semaphore *sem) +{ + might_sleep(); + rwsem_acquire(&sem->dep_map, 0, 0, _RET_IP_); + + if (LOCK_CONTENDED_RETURN(sem, __down_write_trylock, + __down_write_interruptible)) { + rwsem_release(&sem->dep_map, _RET_IP_); + return -EINTR; + } + + return 0; +} +EXPORT_SYMBOL(down_write_interruptible); + /* * lock for writing */