Message ID | 20150722211535.GA20007@redhat.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On Wed, Jul 22, 2015 at 11:15:35PM +0200, Oleg Nesterov wrote: > Add percpu_rwsem_release() and percpu_rwsem_acquire() for the users > which need to return to userspace with percpu-rwsem lock held and/or > pass the ownership to another thread. > > TODO: change percpu_rwsem_release() to use rwsem_clear_owner(). We can > either fold kernel/locking/rwsem.h into include/linux/rwsem.h, or add > the non-inline percpu_rwsem_clear_owner(). > > Signed-off-by: Oleg Nesterov <oleg@redhat.com> > --- > include/linux/percpu-rwsem.h | 19 +++++++++++++++++++ > 1 files changed, 19 insertions(+), 0 deletions(-) > > diff --git a/include/linux/percpu-rwsem.h b/include/linux/percpu-rwsem.h > index 3ebf982..06af654 100644 > --- a/include/linux/percpu-rwsem.h > +++ b/include/linux/percpu-rwsem.h > @@ -33,4 +33,23 @@ extern void percpu_free_rwsem(struct percpu_rw_semaphore *); > __percpu_init_rwsem(brw, #brw, &rwsem_key); \ > }) > > + > +#define percpu_rwsem_is_held(sem) lockdep_is_held(&(sem)->rw_sem) > + > +static inline void percpu_rwsem_release(struct percpu_rw_semaphore *sem, > + bool read, unsigned long ip) > +{ > + lock_release(&sem->rw_sem.dep_map, 1, ip); > +#ifdef CONFIG_RWSEM_SPIN_ON_OWNER > + if (!read) > + sem->rw_sem.owner = NULL; > +#endif > +} > + > +static inline void percpu_rwsem_acquire(struct percpu_rw_semaphore *sem, > + bool read, unsigned long ip) > +{ > + lock_acquire(&sem->rw_sem.dep_map, 0, 1, read, 1, NULL, ip); > +} This is of course entirely vile.. Can't we open code that in the freezer code? Having helpers here might give some people the impression that this is a sane thing to do. Also, when you do that in the freezer, put a big honking comment on it. -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On 07/31, Peter Zijlstra wrote: > > On Wed, Jul 22, 2015 at 11:15:35PM +0200, Oleg Nesterov wrote: > > + > > +static inline void percpu_rwsem_release(struct percpu_rw_semaphore *sem, > > + bool read, unsigned long ip) > > +{ > > + lock_release(&sem->rw_sem.dep_map, 1, ip); > > +#ifdef CONFIG_RWSEM_SPIN_ON_OWNER > > + if (!read) > > + sem->rw_sem.owner = NULL; > > +#endif > > +} > > + > > +static inline void percpu_rwsem_acquire(struct percpu_rw_semaphore *sem, > > + bool read, unsigned long ip) > > +{ > > + lock_acquire(&sem->rw_sem.dep_map, 0, 1, read, 1, NULL, ip); > > +} > > This is of course entirely vile.. Can't we open code that in the freezer > code? Move these helpers somewhere in fs/super.c ? I don't think we should. All members in struct percpu_rw_semaphore are private, nobody outside of percpu-rwsem.[ch] should touch ->rw_sem at least. > Having helpers here might give some people the impression that > this is a sane thing to do. Yes, but this doesn't differ from other lockdep release/acquire helpers, they should be used with care. BTW, we also need these helpers to add the multi-writer support, but this is almost off-topic right now. > Also, when you do that in the freezer, put a big honking comment on it. OK, I'll update the comment(s). Oleg. -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
diff --git a/include/linux/percpu-rwsem.h b/include/linux/percpu-rwsem.h index 3ebf982..06af654 100644 --- a/include/linux/percpu-rwsem.h +++ b/include/linux/percpu-rwsem.h @@ -33,4 +33,23 @@ extern void percpu_free_rwsem(struct percpu_rw_semaphore *); __percpu_init_rwsem(brw, #brw, &rwsem_key); \ }) + +#define percpu_rwsem_is_held(sem) lockdep_is_held(&(sem)->rw_sem) + +static inline void percpu_rwsem_release(struct percpu_rw_semaphore *sem, + bool read, unsigned long ip) +{ + lock_release(&sem->rw_sem.dep_map, 1, ip); +#ifdef CONFIG_RWSEM_SPIN_ON_OWNER + if (!read) + sem->rw_sem.owner = NULL; +#endif +} + +static inline void percpu_rwsem_acquire(struct percpu_rw_semaphore *sem, + bool read, unsigned long ip) +{ + lock_acquire(&sem->rw_sem.dep_map, 0, 1, read, 1, NULL, ip); +} + #endif
Add percpu_rwsem_release() and percpu_rwsem_acquire() for the users which need to return to userspace with percpu-rwsem lock held and/or pass the ownership to another thread. TODO: change percpu_rwsem_release() to use rwsem_clear_owner(). We can either fold kernel/locking/rwsem.h into include/linux/rwsem.h, or add the non-inline percpu_rwsem_clear_owner(). Signed-off-by: Oleg Nesterov <oleg@redhat.com> --- include/linux/percpu-rwsem.h | 19 +++++++++++++++++++ 1 files changed, 19 insertions(+), 0 deletions(-)