Re: [RFC PATCH v2 2/2] locking/percpu-rwsem: Mark rwsem as non-spinnable in percpu_rwsem_release()
On Tue, May 15, 2018 at 09:57:44AM -0400, Waiman Long wrote: > > Afaict the whole .owner=NULL thing in release already stops the spinners > > dead, and the above 'fixes' the debug splat. And this avoids exposing > > that horrible interface and keeps the mucking private to > > rwsem/percpu_rwsem. > > Actually setting owner to NULL does not stop spinning. The code just > assume that the lock is going to be freed and spin in the outer loop. We > need some special value to indicate that spinning should be stopped. How > about just exposing a special value for that in linux/rwsem.h? Any > suggestion for a good name? RWSEM_NO_OWNER
Re: [RFC PATCH v2 2/2] locking/percpu-rwsem: Mark rwsem as non-spinnable in percpu_rwsem_release()
On Tue, May 15, 2018 at 09:57:44AM -0400, Waiman Long wrote: > > Afaict the whole .owner=NULL thing in release already stops the spinners > > dead, and the above 'fixes' the debug splat. And this avoids exposing > > that horrible interface and keeps the mucking private to > > rwsem/percpu_rwsem. > > Actually setting owner to NULL does not stop spinning. The code just > assume that the lock is going to be freed and spin in the outer loop. We > need some special value to indicate that spinning should be stopped. How > about just exposing a special value for that in linux/rwsem.h? Any > suggestion for a good name? RWSEM_NO_OWNER
Re: [RFC PATCH v2 2/2] locking/percpu-rwsem: Mark rwsem as non-spinnable in percpu_rwsem_release()
On 05/15/2018 04:51 AM, Peter Zijlstra wrote: > On Mon, May 14, 2018 at 03:31:07PM -0400, Waiman Long wrote: >> The percpu_rwsem_release() is called when the ownership of the embedded >> rwsem is to be transferred to another task. The new owner, however, may >> take a while to get the ownership of the lock via percpu_rwsem_acquire(). >> During that period, the rwsem is now marked as writer-owned with no >> optimistic spinning. >> >> Signed-off-by: Waiman Long>> --- >> include/linux/percpu-rwsem.h | 6 +++--- >> 1 file changed, 3 insertions(+), 3 deletions(-) >> >> diff --git a/include/linux/percpu-rwsem.h b/include/linux/percpu-rwsem.h >> index b1f37a8..dd37102 100644 >> --- a/include/linux/percpu-rwsem.h >> +++ b/include/linux/percpu-rwsem.h >> @@ -131,16 +131,16 @@ static inline void percpu_rwsem_release(struct >> percpu_rw_semaphore *sem, >> bool read, unsigned long ip) >> { >> lock_release(>rw_sem.dep_map, 1, ip); >> -#ifdef CONFIG_RWSEM_SPIN_ON_OWNER >> if (!read) >> -sem->rw_sem.owner = NULL; >> -#endif >> +rwsem_set_writer_owned_nospin(>rw_sem); >> } >> >> static inline void percpu_rwsem_acquire(struct percpu_rw_semaphore *sem, >> bool read, unsigned long ip) >> { >> lock_acquire(>rw_sem.dep_map, 0, 1, read, 1, NULL, ip); >> +if (!read) >> +rwsem_set_writer_owned(>rw_sem, current); >> } > So what's wrong with adding: > > if (!read) > sem->rw_sem.owner = current; > > ? Yes, we can certainly do that within a "#ifdef" block. > > Afaict the whole .owner=NULL thing in release already stops the spinners > dead, and the above 'fixes' the debug splat. And this avoids exposing > that horrible interface and keeps the mucking private to > rwsem/percpu_rwsem. Actually setting owner to NULL does not stop spinning. The code just assume that the lock is going to be freed and spin in the outer loop. We need some special value to indicate that spinning should be stopped. How about just exposing a special value for that in linux/rwsem.h? Any suggestion for a good name? Cheers, Longman
Re: [RFC PATCH v2 2/2] locking/percpu-rwsem: Mark rwsem as non-spinnable in percpu_rwsem_release()
On 05/15/2018 04:51 AM, Peter Zijlstra wrote: > On Mon, May 14, 2018 at 03:31:07PM -0400, Waiman Long wrote: >> The percpu_rwsem_release() is called when the ownership of the embedded >> rwsem is to be transferred to another task. The new owner, however, may >> take a while to get the ownership of the lock via percpu_rwsem_acquire(). >> During that period, the rwsem is now marked as writer-owned with no >> optimistic spinning. >> >> Signed-off-by: Waiman Long >> --- >> include/linux/percpu-rwsem.h | 6 +++--- >> 1 file changed, 3 insertions(+), 3 deletions(-) >> >> diff --git a/include/linux/percpu-rwsem.h b/include/linux/percpu-rwsem.h >> index b1f37a8..dd37102 100644 >> --- a/include/linux/percpu-rwsem.h >> +++ b/include/linux/percpu-rwsem.h >> @@ -131,16 +131,16 @@ static inline void percpu_rwsem_release(struct >> percpu_rw_semaphore *sem, >> bool read, unsigned long ip) >> { >> lock_release(>rw_sem.dep_map, 1, ip); >> -#ifdef CONFIG_RWSEM_SPIN_ON_OWNER >> if (!read) >> -sem->rw_sem.owner = NULL; >> -#endif >> +rwsem_set_writer_owned_nospin(>rw_sem); >> } >> >> static inline void percpu_rwsem_acquire(struct percpu_rw_semaphore *sem, >> bool read, unsigned long ip) >> { >> lock_acquire(>rw_sem.dep_map, 0, 1, read, 1, NULL, ip); >> +if (!read) >> +rwsem_set_writer_owned(>rw_sem, current); >> } > So what's wrong with adding: > > if (!read) > sem->rw_sem.owner = current; > > ? Yes, we can certainly do that within a "#ifdef" block. > > Afaict the whole .owner=NULL thing in release already stops the spinners > dead, and the above 'fixes' the debug splat. And this avoids exposing > that horrible interface and keeps the mucking private to > rwsem/percpu_rwsem. Actually setting owner to NULL does not stop spinning. The code just assume that the lock is going to be freed and spin in the outer loop. We need some special value to indicate that spinning should be stopped. How about just exposing a special value for that in linux/rwsem.h? Any suggestion for a good name? Cheers, Longman
Re: [RFC PATCH v2 2/2] locking/percpu-rwsem: Mark rwsem as non-spinnable in percpu_rwsem_release()
On 05/15/2018 01:42 AM, Amir Goldstein wrote: > On Mon, May 14, 2018 at 10:31 PM, Waiman Longwrote: >> The percpu_rwsem_release() is called when the ownership of the embedded >> rwsem is to be transferred to another task. The new owner, however, may >> take a while to get the ownership of the lock via percpu_rwsem_acquire(). >> During that period, the rwsem is now marked as writer-owned with no >> optimistic spinning. >> > Waiman, > > Thanks for the fix. I will test it soon. > > For this commit message I suggest that you add parts of the reproducer > found here: > https://marc.info/?l=linux-fsdevel=152622016219975=2 > > Thanks, > Amir. Sure. I will add that to the commit log. Cheers, Longman
Re: [RFC PATCH v2 2/2] locking/percpu-rwsem: Mark rwsem as non-spinnable in percpu_rwsem_release()
On 05/15/2018 01:42 AM, Amir Goldstein wrote: > On Mon, May 14, 2018 at 10:31 PM, Waiman Long wrote: >> The percpu_rwsem_release() is called when the ownership of the embedded >> rwsem is to be transferred to another task. The new owner, however, may >> take a while to get the ownership of the lock via percpu_rwsem_acquire(). >> During that period, the rwsem is now marked as writer-owned with no >> optimistic spinning. >> > Waiman, > > Thanks for the fix. I will test it soon. > > For this commit message I suggest that you add parts of the reproducer > found here: > https://marc.info/?l=linux-fsdevel=152622016219975=2 > > Thanks, > Amir. Sure. I will add that to the commit log. Cheers, Longman
Re: [RFC PATCH v2 2/2] locking/percpu-rwsem: Mark rwsem as non-spinnable in percpu_rwsem_release()
On Tue, May 15, 2018 at 02:45:32PM +0200, Oleg Nesterov wrote: > On 05/15, Peter Zijlstra wrote: > > > > > > Afaict the whole .owner=NULL thing in release already stops the spinners > > > > > > Not really, the new writer will spin in this case, afaics. > > > > > > But this is another problem and probably we do not care. The new writer is > > > almost impossible in this particular case, another freeze_super() should > > > notice frozen != SB_UNFROZEN and return EBUSY. > > > > rwsem_spin_on_owner() checks rwsem_owner_is_writer(), which does owner > > && owner != RWSEM_READER_OWNED, which will fail for !owner. > > Yep. So rwsem_spin_on_owner() goes to "out:" and returns > !rwsem_owner_is_reader() == T. > > IOW, afaics owner == NULL means "spin unconditionally", I guess this is for > the case when the new writer is going to do rwsem_set_owner() or up_write() > has already called rwsem_clear_owner() but didn't do up_write() yet. > > Probably makes sense, but the code is not very clean, Arrgh, you're right... I hate this rwsem code. Some day I'll finish the atomic_long_t version, which similar to mutex, merges the owner and 'count' fields.
Re: [RFC PATCH v2 2/2] locking/percpu-rwsem: Mark rwsem as non-spinnable in percpu_rwsem_release()
On Tue, May 15, 2018 at 02:45:32PM +0200, Oleg Nesterov wrote: > On 05/15, Peter Zijlstra wrote: > > > > > > Afaict the whole .owner=NULL thing in release already stops the spinners > > > > > > Not really, the new writer will spin in this case, afaics. > > > > > > But this is another problem and probably we do not care. The new writer is > > > almost impossible in this particular case, another freeze_super() should > > > notice frozen != SB_UNFROZEN and return EBUSY. > > > > rwsem_spin_on_owner() checks rwsem_owner_is_writer(), which does owner > > && owner != RWSEM_READER_OWNED, which will fail for !owner. > > Yep. So rwsem_spin_on_owner() goes to "out:" and returns > !rwsem_owner_is_reader() == T. > > IOW, afaics owner == NULL means "spin unconditionally", I guess this is for > the case when the new writer is going to do rwsem_set_owner() or up_write() > has already called rwsem_clear_owner() but didn't do up_write() yet. > > Probably makes sense, but the code is not very clean, Arrgh, you're right... I hate this rwsem code. Some day I'll finish the atomic_long_t version, which similar to mutex, merges the owner and 'count' fields.
Re: [RFC PATCH v2 2/2] locking/percpu-rwsem: Mark rwsem as non-spinnable in percpu_rwsem_release()
On 05/15, Peter Zijlstra wrote: > > > > Afaict the whole .owner=NULL thing in release already stops the spinners > > > > Not really, the new writer will spin in this case, afaics. > > > > But this is another problem and probably we do not care. The new writer is > > almost impossible in this particular case, another freeze_super() should > > notice frozen != SB_UNFROZEN and return EBUSY. > > rwsem_spin_on_owner() checks rwsem_owner_is_writer(), which does owner > && owner != RWSEM_READER_OWNED, which will fail for !owner. Yep. So rwsem_spin_on_owner() goes to "out:" and returns !rwsem_owner_is_reader() == T. IOW, afaics owner == NULL means "spin unconditionally", I guess this is for the case when the new writer is going to do rwsem_set_owner() or up_write() has already called rwsem_clear_owner() but didn't do up_write() yet. Probably makes sense, but the code is not very clean, > Or am I completely confused again? Or me, I am not sure. Oleg.
Re: [RFC PATCH v2 2/2] locking/percpu-rwsem: Mark rwsem as non-spinnable in percpu_rwsem_release()
On 05/15, Peter Zijlstra wrote: > > > > Afaict the whole .owner=NULL thing in release already stops the spinners > > > > Not really, the new writer will spin in this case, afaics. > > > > But this is another problem and probably we do not care. The new writer is > > almost impossible in this particular case, another freeze_super() should > > notice frozen != SB_UNFROZEN and return EBUSY. > > rwsem_spin_on_owner() checks rwsem_owner_is_writer(), which does owner > && owner != RWSEM_READER_OWNED, which will fail for !owner. Yep. So rwsem_spin_on_owner() goes to "out:" and returns !rwsem_owner_is_reader() == T. IOW, afaics owner == NULL means "spin unconditionally", I guess this is for the case when the new writer is going to do rwsem_set_owner() or up_write() has already called rwsem_clear_owner() but didn't do up_write() yet. Probably makes sense, but the code is not very clean, > Or am I completely confused again? Or me, I am not sure. Oleg.
Re: [RFC PATCH v2 2/2] locking/percpu-rwsem: Mark rwsem as non-spinnable in percpu_rwsem_release()
On Tue, May 15, 2018 at 01:06:33PM +0200, Oleg Nesterov wrote: > On 05/15, Peter Zijlstra wrote: > > > > So what's wrong with adding: > > > > if (!read) > > sem->rw_sem.owner = current; > > Agreed, I have already suggested this change twice. Except we obviously > need to check CONFIG_RWSEM_SPIN_ON_OWNER (->owner doesn't exists otherwise) > or even CONFIG_DEBUG_RWSEMS to make the purpose more clear. Right, details ;-) > > Afaict the whole .owner=NULL thing in release already stops the spinners > > Not really, the new writer will spin in this case, afaics. > > But this is another problem and probably we do not care. The new writer is > almost impossible in this particular case, another freeze_super() should > notice frozen != SB_UNFROZEN and return EBUSY. rwsem_spin_on_owner() checks rwsem_owner_is_writer(), which does owner && owner != RWSEM_READER_OWNED, which will fail for !owner. Or am I completely confused again? > > and the above 'fixes' the debug splat. > > Yes. > > Waiman, can't we trivially fix the problem first? Then we can add the helpers > and think about other improvements. It is really simple; we're not going to add public (and EXPORT'ed to boot) interfaces to rwsem for this.
Re: [RFC PATCH v2 2/2] locking/percpu-rwsem: Mark rwsem as non-spinnable in percpu_rwsem_release()
On Tue, May 15, 2018 at 01:06:33PM +0200, Oleg Nesterov wrote: > On 05/15, Peter Zijlstra wrote: > > > > So what's wrong with adding: > > > > if (!read) > > sem->rw_sem.owner = current; > > Agreed, I have already suggested this change twice. Except we obviously > need to check CONFIG_RWSEM_SPIN_ON_OWNER (->owner doesn't exists otherwise) > or even CONFIG_DEBUG_RWSEMS to make the purpose more clear. Right, details ;-) > > Afaict the whole .owner=NULL thing in release already stops the spinners > > Not really, the new writer will spin in this case, afaics. > > But this is another problem and probably we do not care. The new writer is > almost impossible in this particular case, another freeze_super() should > notice frozen != SB_UNFROZEN and return EBUSY. rwsem_spin_on_owner() checks rwsem_owner_is_writer(), which does owner && owner != RWSEM_READER_OWNED, which will fail for !owner. Or am I completely confused again? > > and the above 'fixes' the debug splat. > > Yes. > > Waiman, can't we trivially fix the problem first? Then we can add the helpers > and think about other improvements. It is really simple; we're not going to add public (and EXPORT'ed to boot) interfaces to rwsem for this.
Re: [RFC PATCH v2 2/2] locking/percpu-rwsem: Mark rwsem as non-spinnable in percpu_rwsem_release()
On 05/15, Jan Kara wrote: > > Now this behavior upsets lockdep and that's why we fool it by telling the > semaphore got released before returning to userspace (through > percpu_rwsem_release() helper) and similarly we tell lockdep we've got the > semaphore when an unfreeze syscall is called by percpu_rwsem_acquire(). Now > Amir has discovered that also rwsem debugging code gets confused by this > behavior Yes, plus someone else has already reported the problem a month ago, > and previously also someone noticed that rwsem spinning does not > make sense and can be broken by this behavior. Well, this doesn't really matter but again, freeze_super() checks frozen == SB_UNFROZEN under sb->s_umount and only then does sb_wait_write(), when the previous writer has already realeased this lock. So the new writer will never spin after lockdep_sb_freeze_release() clears ->owner. Oleg.
Re: [RFC PATCH v2 2/2] locking/percpu-rwsem: Mark rwsem as non-spinnable in percpu_rwsem_release()
On 05/15, Jan Kara wrote: > > Now this behavior upsets lockdep and that's why we fool it by telling the > semaphore got released before returning to userspace (through > percpu_rwsem_release() helper) and similarly we tell lockdep we've got the > semaphore when an unfreeze syscall is called by percpu_rwsem_acquire(). Now > Amir has discovered that also rwsem debugging code gets confused by this > behavior Yes, plus someone else has already reported the problem a month ago, > and previously also someone noticed that rwsem spinning does not > make sense and can be broken by this behavior. Well, this doesn't really matter but again, freeze_super() checks frozen == SB_UNFROZEN under sb->s_umount and only then does sb_wait_write(), when the previous writer has already realeased this lock. So the new writer will never spin after lockdep_sb_freeze_release() clears ->owner. Oleg.
Re: [RFC PATCH v2 2/2] locking/percpu-rwsem: Mark rwsem as non-spinnable in percpu_rwsem_release()
On 05/15, Peter Zijlstra wrote: > > So what's wrong with adding: > > if (!read) > sem->rw_sem.owner = current; Agreed, I have already suggested this change twice. Except we obviously need to check CONFIG_RWSEM_SPIN_ON_OWNER (->owner doesn't exists otherwise) or even CONFIG_DEBUG_RWSEMS to make the purpose more clear. > Afaict the whole .owner=NULL thing in release already stops the spinners Not really, the new writer will spin in this case, afaics. But this is another problem and probably we do not care. The new writer is almost impossible in this particular case, another freeze_super() should notice frozen != SB_UNFROZEN and return EBUSY. > and the above 'fixes' the debug splat. Yes. Waiman, can't we trivially fix the problem first? Then we can add the helpers and think about other improvements. Oleg.
Re: [RFC PATCH v2 2/2] locking/percpu-rwsem: Mark rwsem as non-spinnable in percpu_rwsem_release()
On 05/15, Peter Zijlstra wrote: > > So what's wrong with adding: > > if (!read) > sem->rw_sem.owner = current; Agreed, I have already suggested this change twice. Except we obviously need to check CONFIG_RWSEM_SPIN_ON_OWNER (->owner doesn't exists otherwise) or even CONFIG_DEBUG_RWSEMS to make the purpose more clear. > Afaict the whole .owner=NULL thing in release already stops the spinners Not really, the new writer will spin in this case, afaics. But this is another problem and probably we do not care. The new writer is almost impossible in this particular case, another freeze_super() should notice frozen != SB_UNFROZEN and return EBUSY. > and the above 'fixes' the debug splat. Yes. Waiman, can't we trivially fix the problem first? Then we can add the helpers and think about other improvements. Oleg.
Re: [RFC PATCH v2 2/2] locking/percpu-rwsem: Mark rwsem as non-spinnable in percpu_rwsem_release()
On Tue 15-05-18 10:35:25, Peter Zijlstra wrote: > On Mon, May 14, 2018 at 03:31:07PM -0400, Waiman Long wrote: > > The percpu_rwsem_release() is called when the ownership of the embedded > > rwsem is to be transferred to another task. The new owner, however, may > > take a while to get the ownership of the lock via percpu_rwsem_acquire(). > > During that period, the rwsem is now marked as writer-owned with no > > optimistic spinning. > > This does not explain the problem sufficiently to even begin considering > if the proposed solution is sensible. So the original problem is following: There is percpu_rw_semaphore in super_block which is used to implement filesystem freezing (actually three of them but that's not really substantial here). This semaphore is acquired for writing when a fs is frozen (i.e., in response to a syscall) and we return to userspace with this semaphore held. Later someone else calls another syscall to unfreeze the filesystem which drops the semaphore. Now this behavior upsets lockdep and that's why we fool it by telling the semaphore got released before returning to userspace (through percpu_rwsem_release() helper) and similarly we tell lockdep we've got the semaphore when an unfreeze syscall is called by percpu_rwsem_acquire(). Now Amir has discovered that also rwsem debugging code gets confused by this behavior and previously also someone noticed that rwsem spinning does not make sense and can be broken by this behavior. So these patches from Waiman try to fix up all these problems... Honza -- Jan KaraSUSE Labs, CR
Re: [RFC PATCH v2 2/2] locking/percpu-rwsem: Mark rwsem as non-spinnable in percpu_rwsem_release()
On Tue 15-05-18 10:35:25, Peter Zijlstra wrote: > On Mon, May 14, 2018 at 03:31:07PM -0400, Waiman Long wrote: > > The percpu_rwsem_release() is called when the ownership of the embedded > > rwsem is to be transferred to another task. The new owner, however, may > > take a while to get the ownership of the lock via percpu_rwsem_acquire(). > > During that period, the rwsem is now marked as writer-owned with no > > optimistic spinning. > > This does not explain the problem sufficiently to even begin considering > if the proposed solution is sensible. So the original problem is following: There is percpu_rw_semaphore in super_block which is used to implement filesystem freezing (actually three of them but that's not really substantial here). This semaphore is acquired for writing when a fs is frozen (i.e., in response to a syscall) and we return to userspace with this semaphore held. Later someone else calls another syscall to unfreeze the filesystem which drops the semaphore. Now this behavior upsets lockdep and that's why we fool it by telling the semaphore got released before returning to userspace (through percpu_rwsem_release() helper) and similarly we tell lockdep we've got the semaphore when an unfreeze syscall is called by percpu_rwsem_acquire(). Now Amir has discovered that also rwsem debugging code gets confused by this behavior and previously also someone noticed that rwsem spinning does not make sense and can be broken by this behavior. So these patches from Waiman try to fix up all these problems... Honza -- Jan Kara SUSE Labs, CR
Re: [RFC PATCH v2 2/2] locking/percpu-rwsem: Mark rwsem as non-spinnable in percpu_rwsem_release()
On Mon, May 14, 2018 at 03:31:07PM -0400, Waiman Long wrote: > The percpu_rwsem_release() is called when the ownership of the embedded > rwsem is to be transferred to another task. The new owner, however, may > take a while to get the ownership of the lock via percpu_rwsem_acquire(). > During that period, the rwsem is now marked as writer-owned with no > optimistic spinning. > > Signed-off-by: Waiman Long> --- > include/linux/percpu-rwsem.h | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/include/linux/percpu-rwsem.h b/include/linux/percpu-rwsem.h > index b1f37a8..dd37102 100644 > --- a/include/linux/percpu-rwsem.h > +++ b/include/linux/percpu-rwsem.h > @@ -131,16 +131,16 @@ static inline void percpu_rwsem_release(struct > percpu_rw_semaphore *sem, > bool read, unsigned long ip) > { > lock_release(>rw_sem.dep_map, 1, ip); > -#ifdef CONFIG_RWSEM_SPIN_ON_OWNER > if (!read) > - sem->rw_sem.owner = NULL; > -#endif > + rwsem_set_writer_owned_nospin(>rw_sem); > } > > static inline void percpu_rwsem_acquire(struct percpu_rw_semaphore *sem, > bool read, unsigned long ip) > { > lock_acquire(>rw_sem.dep_map, 0, 1, read, 1, NULL, ip); > + if (!read) > + rwsem_set_writer_owned(>rw_sem, current); > } So what's wrong with adding: if (!read) sem->rw_sem.owner = current; ? Afaict the whole .owner=NULL thing in release already stops the spinners dead, and the above 'fixes' the debug splat. And this avoids exposing that horrible interface and keeps the mucking private to rwsem/percpu_rwsem.
Re: [RFC PATCH v2 2/2] locking/percpu-rwsem: Mark rwsem as non-spinnable in percpu_rwsem_release()
On Mon, May 14, 2018 at 03:31:07PM -0400, Waiman Long wrote: > The percpu_rwsem_release() is called when the ownership of the embedded > rwsem is to be transferred to another task. The new owner, however, may > take a while to get the ownership of the lock via percpu_rwsem_acquire(). > During that period, the rwsem is now marked as writer-owned with no > optimistic spinning. > > Signed-off-by: Waiman Long > --- > include/linux/percpu-rwsem.h | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/include/linux/percpu-rwsem.h b/include/linux/percpu-rwsem.h > index b1f37a8..dd37102 100644 > --- a/include/linux/percpu-rwsem.h > +++ b/include/linux/percpu-rwsem.h > @@ -131,16 +131,16 @@ static inline void percpu_rwsem_release(struct > percpu_rw_semaphore *sem, > bool read, unsigned long ip) > { > lock_release(>rw_sem.dep_map, 1, ip); > -#ifdef CONFIG_RWSEM_SPIN_ON_OWNER > if (!read) > - sem->rw_sem.owner = NULL; > -#endif > + rwsem_set_writer_owned_nospin(>rw_sem); > } > > static inline void percpu_rwsem_acquire(struct percpu_rw_semaphore *sem, > bool read, unsigned long ip) > { > lock_acquire(>rw_sem.dep_map, 0, 1, read, 1, NULL, ip); > + if (!read) > + rwsem_set_writer_owned(>rw_sem, current); > } So what's wrong with adding: if (!read) sem->rw_sem.owner = current; ? Afaict the whole .owner=NULL thing in release already stops the spinners dead, and the above 'fixes' the debug splat. And this avoids exposing that horrible interface and keeps the mucking private to rwsem/percpu_rwsem.
Re: [RFC PATCH v2 2/2] locking/percpu-rwsem: Mark rwsem as non-spinnable in percpu_rwsem_release()
On Mon, May 14, 2018 at 03:31:07PM -0400, Waiman Long wrote: > The percpu_rwsem_release() is called when the ownership of the embedded > rwsem is to be transferred to another task. The new owner, however, may > take a while to get the ownership of the lock via percpu_rwsem_acquire(). > During that period, the rwsem is now marked as writer-owned with no > optimistic spinning. This does not explain the problem sufficiently to even begin considering if the proposed solution is sensible.
Re: [RFC PATCH v2 2/2] locking/percpu-rwsem: Mark rwsem as non-spinnable in percpu_rwsem_release()
On Mon, May 14, 2018 at 03:31:07PM -0400, Waiman Long wrote: > The percpu_rwsem_release() is called when the ownership of the embedded > rwsem is to be transferred to another task. The new owner, however, may > take a while to get the ownership of the lock via percpu_rwsem_acquire(). > During that period, the rwsem is now marked as writer-owned with no > optimistic spinning. This does not explain the problem sufficiently to even begin considering if the proposed solution is sensible.
Re: [RFC PATCH v2 2/2] locking/percpu-rwsem: Mark rwsem as non-spinnable in percpu_rwsem_release()
On Tue, May 15, 2018 at 8:42 AM, Amir Goldsteinwrote: > On Mon, May 14, 2018 at 10:31 PM, Waiman Long wrote: >> The percpu_rwsem_release() is called when the ownership of the embedded >> rwsem is to be transferred to another task. The new owner, however, may >> take a while to get the ownership of the lock via percpu_rwsem_acquire(). >> During that period, the rwsem is now marked as writer-owned with no >> optimistic spinning. >> > > Waiman, > > Thanks for the fix. I will test it soon. > > For this commit message I suggest that you add parts of the reproducer > found here: > https://marc.info/?l=linux-fsdevel=152622016219975=2 > fsfreeze is happy with these changes. You may add: Tested-by: Amir Goldstein Thanks, Amir.
Re: [RFC PATCH v2 2/2] locking/percpu-rwsem: Mark rwsem as non-spinnable in percpu_rwsem_release()
On Tue, May 15, 2018 at 8:42 AM, Amir Goldstein wrote: > On Mon, May 14, 2018 at 10:31 PM, Waiman Long wrote: >> The percpu_rwsem_release() is called when the ownership of the embedded >> rwsem is to be transferred to another task. The new owner, however, may >> take a while to get the ownership of the lock via percpu_rwsem_acquire(). >> During that period, the rwsem is now marked as writer-owned with no >> optimistic spinning. >> > > Waiman, > > Thanks for the fix. I will test it soon. > > For this commit message I suggest that you add parts of the reproducer > found here: > https://marc.info/?l=linux-fsdevel=152622016219975=2 > fsfreeze is happy with these changes. You may add: Tested-by: Amir Goldstein Thanks, Amir.
Re: [RFC PATCH v2 2/2] locking/percpu-rwsem: Mark rwsem as non-spinnable in percpu_rwsem_release()
On Mon, May 14, 2018 at 10:31 PM, Waiman Longwrote: > The percpu_rwsem_release() is called when the ownership of the embedded > rwsem is to be transferred to another task. The new owner, however, may > take a while to get the ownership of the lock via percpu_rwsem_acquire(). > During that period, the rwsem is now marked as writer-owned with no > optimistic spinning. > Waiman, Thanks for the fix. I will test it soon. For this commit message I suggest that you add parts of the reproducer found here: https://marc.info/?l=linux-fsdevel=152622016219975=2 Thanks, Amir. > Signed-off-by: Waiman Long > --- > include/linux/percpu-rwsem.h | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/include/linux/percpu-rwsem.h b/include/linux/percpu-rwsem.h > index b1f37a8..dd37102 100644 > --- a/include/linux/percpu-rwsem.h > +++ b/include/linux/percpu-rwsem.h > @@ -131,16 +131,16 @@ static inline void percpu_rwsem_release(struct > percpu_rw_semaphore *sem, > bool read, unsigned long ip) > { > lock_release(>rw_sem.dep_map, 1, ip); > -#ifdef CONFIG_RWSEM_SPIN_ON_OWNER > if (!read) > - sem->rw_sem.owner = NULL; > -#endif > + rwsem_set_writer_owned_nospin(>rw_sem); > } > > static inline void percpu_rwsem_acquire(struct percpu_rw_semaphore *sem, > bool read, unsigned long ip) > { > lock_acquire(>rw_sem.dep_map, 0, 1, read, 1, NULL, ip); > + if (!read) > + rwsem_set_writer_owned(>rw_sem, current); > } > > #endif > -- > 1.8.3.1 >
Re: [RFC PATCH v2 2/2] locking/percpu-rwsem: Mark rwsem as non-spinnable in percpu_rwsem_release()
On Mon, May 14, 2018 at 10:31 PM, Waiman Long wrote: > The percpu_rwsem_release() is called when the ownership of the embedded > rwsem is to be transferred to another task. The new owner, however, may > take a while to get the ownership of the lock via percpu_rwsem_acquire(). > During that period, the rwsem is now marked as writer-owned with no > optimistic spinning. > Waiman, Thanks for the fix. I will test it soon. For this commit message I suggest that you add parts of the reproducer found here: https://marc.info/?l=linux-fsdevel=152622016219975=2 Thanks, Amir. > Signed-off-by: Waiman Long > --- > include/linux/percpu-rwsem.h | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/include/linux/percpu-rwsem.h b/include/linux/percpu-rwsem.h > index b1f37a8..dd37102 100644 > --- a/include/linux/percpu-rwsem.h > +++ b/include/linux/percpu-rwsem.h > @@ -131,16 +131,16 @@ static inline void percpu_rwsem_release(struct > percpu_rw_semaphore *sem, > bool read, unsigned long ip) > { > lock_release(>rw_sem.dep_map, 1, ip); > -#ifdef CONFIG_RWSEM_SPIN_ON_OWNER > if (!read) > - sem->rw_sem.owner = NULL; > -#endif > + rwsem_set_writer_owned_nospin(>rw_sem); > } > > static inline void percpu_rwsem_acquire(struct percpu_rw_semaphore *sem, > bool read, unsigned long ip) > { > lock_acquire(>rw_sem.dep_map, 0, 1, read, 1, NULL, ip); > + if (!read) > + rwsem_set_writer_owned(>rw_sem, current); > } > > #endif > -- > 1.8.3.1 >