Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 587E5C282D7 for ; Wed, 13 Feb 2019 14:55:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 33FEE222C1 for ; Wed, 13 Feb 2019 14:55:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2403933AbfBMOy6 (ORCPT ); Wed, 13 Feb 2019 09:54:58 -0500 Received: from mx2.suse.de ([195.135.220.15]:60242 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1731302AbfBMOy5 (ORCPT ); Wed, 13 Feb 2019 09:54:57 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id D43F1AD27; Wed, 13 Feb 2019 14:54:55 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 53BE91E150E; Wed, 13 Feb 2019 15:54:54 +0100 (CET) From: Jan Kara To: Cc: Amir Goldstein , Konstantin Khlebnikov , Vivek Trivedi , Orion Poplawski , Jan Kara Subject: [PATCH 2/6] fanotify: Move locking inside get_one_event() Date: Wed, 13 Feb 2019 15:54:39 +0100 Message-Id: <20190213145443.26836-3-jack@suse.cz> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20190213145443.26836-1-jack@suse.cz> References: <20190213145443.26836-1-jack@suse.cz> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org get_one_event() has a single caller and that just locks notification_lock around the call. Move locking inside get_one_event() as that will make using ->response field for permission event state easier. Signed-off-by: Jan Kara --- fs/notify/fanotify/fanotify_user.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c index 908ebc421d15..4e36f5642797 100644 --- a/fs/notify/fanotify/fanotify_user.c +++ b/fs/notify/fanotify/fanotify_user.c @@ -51,25 +51,25 @@ struct kmem_cache *fanotify_perm_event_cachep __read_mostly; * Get an fsnotify notification event if one exists and is small * enough to fit in "count". Return an error pointer if the count * is not large enough. - * - * Called with the group->notification_lock held. */ static struct fsnotify_event *get_one_event(struct fsnotify_group *group, size_t count) { - assert_spin_locked(&group->notification_lock); + struct fsnotify_event *event = NULL; pr_debug("%s: group=%p count=%zd\n", __func__, group, count); - + spin_lock(&group->notification_lock); if (fsnotify_notify_queue_is_empty(group)) - return NULL; + goto out; - if (FAN_EVENT_METADATA_LEN > count) - return ERR_PTR(-EINVAL); - - /* held the notification_lock the whole time, so this is the - * same event we peeked above */ - return fsnotify_remove_first_event(group); + if (FAN_EVENT_METADATA_LEN > count) { + event = ERR_PTR(-EINVAL); + goto out; + } + event = fsnotify_remove_first_event(group); +out: + spin_unlock(&group->notification_lock); + return event; } static int create_fd(struct fsnotify_group *group, @@ -261,10 +261,7 @@ static ssize_t fanotify_read(struct file *file, char __user *buf, add_wait_queue(&group->notification_waitq, &wait); while (1) { - spin_lock(&group->notification_lock); kevent = get_one_event(group, count); - spin_unlock(&group->notification_lock); - if (IS_ERR(kevent)) { ret = PTR_ERR(kevent); break; -- 2.16.4