From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mout.gmx.net ([212.227.15.15]:56025 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1760873AbcINROi (ORCPT ); Wed, 14 Sep 2016 13:14:38 -0400 Subject: Re: [PATCH 6/6] fanotify: Fix possible false warning when freeing events To: Jan Kara , Andrew Morton References: <1473797711-14111-1-git-send-email-jack@suse.cz> <1473797711-14111-7-git-send-email-jack@suse.cz> Cc: linux-fsdevel@vger.kernel.org, Miklos Szeredi , Eric Paris , Al Viro From: Lino Sanfilippo Message-ID: <9f2f7c99-3994-4e7c-247c-9b2ce7bc8f46@gmx.de> Date: Wed, 14 Sep 2016 19:14:31 +0200 MIME-Version: 1.0 In-Reply-To: <1473797711-14111-7-git-send-email-jack@suse.cz> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Sender: linux-fsdevel-owner@vger.kernel.org List-ID: On 13.09.2016 22:15, Jan Kara wrote: > When freeing permission events by fsnotify_destroy_event(), the warning > WARN_ON(!list_empty(&event->list)); > may falsely hit. This is because although fanotify_get_response() saw > event->response set, there is nothing to make sure the current CPU also > sees the removal of the event from the list. Add proper locking around > the WARN_ON() to avoid the false warning. > > Reported-by: Miklos Szeredi > Signed-off-by: Jan Kara > --- > fs/notify/notification.c | 13 +++++++++++-- > 1 file changed, 11 insertions(+), 2 deletions(-) > > diff --git a/fs/notify/notification.c b/fs/notify/notification.c > index 070d255b24a2..6b7f430bb2de 100644 > --- a/fs/notify/notification.c > +++ b/fs/notify/notification.c > @@ -73,8 +73,17 @@ void fsnotify_destroy_event(struct fsnotify_group *group, > /* Overflow events are per-group and we don't want to free them */ > if (!event || event->mask == FS_Q_OVERFLOW) > return; > - /* If the event is still queued, we have a problem... */ > - WARN_ON(!list_empty(&event->list)); > + /* > + * If the event is still queued, we have a problem... Do an unreliable > + * lockless check first to avoid locking in the common case. The > + * locking may be necessary for permission events which got removed > + * from the list by a different CPU than the one freeing the event. > + */ > + if (!list_empty(&event->list)) { > + spin_lock(&group->notification_lock); > + WARN_ON(!list_empty(&event->list)); > + spin_unlock(&group->notification_lock); > + } > group->ops->free_event(event); > } > > Reviewed-by: Lino Sanfilippo