linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] fsnotify: Cleanup spinlock assertions
@ 2016-09-22  9:43 Jan Kara
  2016-09-22 17:45 ` Jeff Layton
  0 siblings, 1 reply; 3+ messages in thread
From: Jan Kara @ 2016-09-22  9:43 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-fsdevel, Heiner Kallweit, Jan Kara

Use assert_spin_locked() macro instead of hand-made BUG_ON statements.

Suggested-by: Heiner Kallweit <hkallweit1@gmail.com>
Signed-off-by: Jan Kara <jack@suse.cz>
---
 fs/notify/fanotify/fanotify_user.c | 3 +--
 fs/notify/notification.c           | 9 +++------
 2 files changed, 4 insertions(+), 8 deletions(-)

Andrew, can you please add this cleanup to the fanotify patches you carry?
Thanks!

diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
index 189fab3ac4e6..7ebfca6a1427 100644
--- a/fs/notify/fanotify/fanotify_user.c
+++ b/fs/notify/fanotify/fanotify_user.c
@@ -54,8 +54,7 @@ struct kmem_cache *fanotify_perm_event_cachep __read_mostly;
 static struct fsnotify_event *get_one_event(struct fsnotify_group *group,
 					    size_t count)
 {
-	BUG_ON(IS_ENABLED(CONFIG_SMP) &&
-	       !spin_is_locked(&group->notification_lock));
+	assert_spin_locked(&group->notification_lock);
 
 	pr_debug("%s: group=%p count=%zd\n", __func__, group, count);
 
diff --git a/fs/notify/notification.c b/fs/notify/notification.c
index 1a8010e7a2a0..66f85c651c52 100644
--- a/fs/notify/notification.c
+++ b/fs/notify/notification.c
@@ -63,8 +63,7 @@ EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
 /* return true if the notify queue is empty, false otherwise */
 bool fsnotify_notify_queue_is_empty(struct fsnotify_group *group)
 {
-	BUG_ON(IS_ENABLED(CONFIG_SMP) &&
-	       !spin_is_locked(&group->notification_lock));
+	assert_spin_locked(&group->notification_lock);
 	return list_empty(&group->notification_list) ? true : false;
 }
 
@@ -149,8 +148,7 @@ struct fsnotify_event *fsnotify_remove_first_event(struct fsnotify_group *group)
 {
 	struct fsnotify_event *event;
 
-	BUG_ON(IS_ENABLED(CONFIG_SMP) &&
-	       !spin_is_locked(&group->notification_lock));
+	assert_spin_locked(&group->notification_lock);
 
 	pr_debug("%s: group=%p\n", __func__, group);
 
@@ -172,8 +170,7 @@ struct fsnotify_event *fsnotify_remove_first_event(struct fsnotify_group *group)
  */
 struct fsnotify_event *fsnotify_peek_first_event(struct fsnotify_group *group)
 {
-	BUG_ON(IS_ENABLED(CONFIG_SMP) &&
-	       !spin_is_locked(&group->notification_lock));
+	assert_spin_locked(&group->notification_lock);
 
 	return list_first_entry(&group->notification_list,
 				struct fsnotify_event, list);
-- 
2.6.6


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] fsnotify: Cleanup spinlock assertions
  2016-09-22  9:43 [PATCH] fsnotify: Cleanup spinlock assertions Jan Kara
@ 2016-09-22 17:45 ` Jeff Layton
  2016-09-23  8:14   ` Jan Kara
  0 siblings, 1 reply; 3+ messages in thread
From: Jeff Layton @ 2016-09-22 17:45 UTC (permalink / raw)
  To: Jan Kara, Andrew Morton; +Cc: linux-fsdevel, Heiner Kallweit

On Thu, 2016-09-22 at 11:43 +0200, Jan Kara wrote:
> Use assert_spin_locked() macro instead of hand-made BUG_ON statements.
> 
> Suggested-by: Heiner Kallweit <hkallweit1@gmail.com>
> Signed-off-by: Jan Kara <jack@suse.cz>
> ---
>  fs/notify/fanotify/fanotify_user.c | 3 +--
>  fs/notify/notification.c           | 9 +++------
>  2 files changed, 4 insertions(+), 8 deletions(-)
> 
> Andrew, can you please add this cleanup to the fanotify patches you carry?
> Thanks!
> 
> diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
> index 189fab3ac4e6..7ebfca6a1427 100644
> --- a/fs/notify/fanotify/fanotify_user.c
> +++ b/fs/notify/fanotify/fanotify_user.c
> @@ -54,8 +54,7 @@ struct kmem_cache *fanotify_perm_event_cachep __read_mostly;
>  static struct fsnotify_event *get_one_event(struct fsnotify_group *group,
>  					    size_t count)
>  {
> -	BUG_ON(IS_ENABLED(CONFIG_SMP) &&
> -	       !spin_is_locked(&group->notification_lock));
> +	assert_spin_locked(&group->notification_lock);
>  
>  	pr_debug("%s: group=%p count=%zd\n", __func__, group, count);
>  
> diff --git a/fs/notify/notification.c b/fs/notify/notification.c
> index 1a8010e7a2a0..66f85c651c52 100644
> --- a/fs/notify/notification.c
> +++ b/fs/notify/notification.c
> @@ -63,8 +63,7 @@ EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
>  /* return true if the notify queue is empty, false otherwise */
>  bool fsnotify_notify_queue_is_empty(struct fsnotify_group *group)
>  {
> -	BUG_ON(IS_ENABLED(CONFIG_SMP) &&
> -	       !spin_is_locked(&group->notification_lock));
> +	assert_spin_locked(&group->notification_lock);
>  	return list_empty(&group->notification_list) ? true : false;
>  }
>  
> @@ -149,8 +148,7 @@ struct fsnotify_event *fsnotify_remove_first_event(struct fsnotify_group *group)
>  {
>  	struct fsnotify_event *event;
>  
> -	BUG_ON(IS_ENABLED(CONFIG_SMP) &&
> -	       !spin_is_locked(&group->notification_lock));
> +	assert_spin_locked(&group->notification_lock);
>  
>  	pr_debug("%s: group=%p\n", __func__, group);
>  
> @@ -172,8 +170,7 @@ struct fsnotify_event *fsnotify_remove_first_event(struct fsnotify_group *group)
>   */
>  struct fsnotify_event *fsnotify_peek_first_event(struct fsnotify_group *group)
>  {
> -	BUG_ON(IS_ENABLED(CONFIG_SMP) &&
> -	       !spin_is_locked(&group->notification_lock));
> +	assert_spin_locked(&group->notification_lock);
>  
>  	return list_first_entry(&group->notification_list,
>  				struct fsnotify_event, list);

Much cleaner.

That said, I have a personal preference for lockdep_assert_held() in
these situations, which not only tells you whether the lock is locked,
but (I believe) whether it was locked by the current task as well.

Theoretically you could have a different task take this spinlock, and
then call into here without holding it and not get the assertion since
it was locked at the time. Of course, that does require lockdep...

In any case, this is still an improvement:

Reviewed-by: Jeff Layton <jlayton@redhat.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] fsnotify: Cleanup spinlock assertions
  2016-09-22 17:45 ` Jeff Layton
@ 2016-09-23  8:14   ` Jan Kara
  0 siblings, 0 replies; 3+ messages in thread
From: Jan Kara @ 2016-09-23  8:14 UTC (permalink / raw)
  To: Jeff Layton; +Cc: Jan Kara, Andrew Morton, linux-fsdevel, Heiner Kallweit

On Thu 22-09-16 13:45:28, Jeff Layton wrote:
> On Thu, 2016-09-22 at 11:43 +0200, Jan Kara wrote:
> > Use assert_spin_locked() macro instead of hand-made BUG_ON statements.
> > 
> > Suggested-by: Heiner Kallweit <hkallweit1@gmail.com>
> > Signed-off-by: Jan Kara <jack@suse.cz>
> > ---
> >  fs/notify/fanotify/fanotify_user.c | 3 +--
> >  fs/notify/notification.c           | 9 +++------
> >  2 files changed, 4 insertions(+), 8 deletions(-)
> > 
> > Andrew, can you please add this cleanup to the fanotify patches you carry?
> > Thanks!
> > 
> > diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
> > index 189fab3ac4e6..7ebfca6a1427 100644
> > --- a/fs/notify/fanotify/fanotify_user.c
> > +++ b/fs/notify/fanotify/fanotify_user.c
> > @@ -54,8 +54,7 @@ struct kmem_cache *fanotify_perm_event_cachep __read_mostly;
> >  static struct fsnotify_event *get_one_event(struct fsnotify_group *group,
> >  					    size_t count)
> >  {
> > -	BUG_ON(IS_ENABLED(CONFIG_SMP) &&
> > -	       !spin_is_locked(&group->notification_lock));
> > +	assert_spin_locked(&group->notification_lock);
> >  
> >  	pr_debug("%s: group=%p count=%zd\n", __func__, group, count);
> >  
> > diff --git a/fs/notify/notification.c b/fs/notify/notification.c
> > index 1a8010e7a2a0..66f85c651c52 100644
> > --- a/fs/notify/notification.c
> > +++ b/fs/notify/notification.c
> > @@ -63,8 +63,7 @@ EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
> >  /* return true if the notify queue is empty, false otherwise */
> >  bool fsnotify_notify_queue_is_empty(struct fsnotify_group *group)
> >  {
> > -	BUG_ON(IS_ENABLED(CONFIG_SMP) &&
> > -	       !spin_is_locked(&group->notification_lock));
> > +	assert_spin_locked(&group->notification_lock);
> >  	return list_empty(&group->notification_list) ? true : false;
> >  }
> >  
> > @@ -149,8 +148,7 @@ struct fsnotify_event *fsnotify_remove_first_event(struct fsnotify_group *group)
> >  {
> >  	struct fsnotify_event *event;
> >  
> > -	BUG_ON(IS_ENABLED(CONFIG_SMP) &&
> > -	       !spin_is_locked(&group->notification_lock));
> > +	assert_spin_locked(&group->notification_lock);
> >  
> >  	pr_debug("%s: group=%p\n", __func__, group);
> >  
> > @@ -172,8 +170,7 @@ struct fsnotify_event *fsnotify_remove_first_event(struct fsnotify_group *group)
> >   */
> >  struct fsnotify_event *fsnotify_peek_first_event(struct fsnotify_group *group)
> >  {
> > -	BUG_ON(IS_ENABLED(CONFIG_SMP) &&
> > -	       !spin_is_locked(&group->notification_lock));
> > +	assert_spin_locked(&group->notification_lock);
> >  
> >  	return list_first_entry(&group->notification_list,
> >  				struct fsnotify_event, list);
> 
> Much cleaner.
> 
> That said, I have a personal preference for lockdep_assert_held() in
> these situations, which not only tells you whether the lock is locked,
> but (I believe) whether it was locked by the current task as well.

Yes, it does.

> Theoretically you could have a different task take this spinlock, and
> then call into here without holding it and not get the assertion since
> it was locked at the time. Of course, that does require lockdep...

Yeah, I personally don't have a strong preference. Both have advantages and
disadvantages - as you said, lockdep_assert_held() is reliable when lockdep
is enabled but there's much less testing happening with lockdep enabled and
also lockdep changes the timing enough that some cases just need not
trigger...
 
> In any case, this is still an improvement:
> 
> Reviewed-by: Jeff Layton <jlayton@redhat.com>

Thanks!

								Honza
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-09-23  8:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-22  9:43 [PATCH] fsnotify: Cleanup spinlock assertions Jan Kara
2016-09-22 17:45 ` Jeff Layton
2016-09-23  8:14   ` Jan Kara

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).