From mboxrd@z Thu Jan 1 00:00:00 1970 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=-7.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS 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 B32BAC0044B for ; Wed, 13 Feb 2019 20:23:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 80DC721872 for ; Wed, 13 Feb 2019 20:23:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="PIgrVtmv" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729947AbfBMUXY (ORCPT ); Wed, 13 Feb 2019 15:23:24 -0500 Received: from mail-yb1-f194.google.com ([209.85.219.194]:38333 "EHLO mail-yb1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726218AbfBMUXX (ORCPT ); Wed, 13 Feb 2019 15:23:23 -0500 Received: by mail-yb1-f194.google.com with SMTP id x9so1459481ybj.5 for ; Wed, 13 Feb 2019 12:23:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=P6SeT3QLG1X4byfBSqiK7YsNv4uv+BxJMOsXg31W+Iw=; b=PIgrVtmvJfqzKkCSFi2MtqLG43/34XEeBZyhB6hAemCKgCODRzZGNiKZci0FGzzuwI DhKQXQAhaAwmRD7Fmiawc0t6LttyxehGoxAk79MEyUnj6xdtgP/cTpLqXJyZG8kH95Em EfUhT3h1GdkjWqgQsfHhy43JgBmFvW9L3yCa9Mef8fjlHTlz30O0vs9zB2TrXdMUifxg LZHPQWo4dBD3jQhVqqXVWO7gj2YBX5g/MmFtAGv+2lfZ7iq14cr8UnvW8b/ySHoDiQhW TuosN8yMcuLMrDxN+/XMwfSH10RvNlktu07XLef48c7oepy/NCFrRGcgW5MMFq5WVTC7 kEJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=P6SeT3QLG1X4byfBSqiK7YsNv4uv+BxJMOsXg31W+Iw=; b=me2lj6BUq9FujcDPvNp77HJRjfHnkD5+tC4ycBcsVlO3v6O10di5nsAuKmkIDqxY2P 6iMHpUamuAvR6eCTmSl6HAQb6qhps3djMirnX1AdJCa/fHb+F1/HGI0jgM3YNv8z65oX Wv+Qx9U+iOqLu85jP0xG/ue2p82sTRijHJYq15GW/1qQcW6KPh4kfMpl2oNW6DX5/jV8 4zwTgBBuHrLu5vQBYTEMxecvmM9pEuOvAGQ1k78Rs2fTZ2vHbjFY7GgQJb/kiSPUIWBF /0WvtYk2B8PdWK5Tzz4YiA0FnQ08hl8tSaUZJfENHlnjJvP6xkBhw88TEmcK6rcaCNxp 6jmg== X-Gm-Message-State: AHQUAubo/6Oo9caQ8K0KSd4FBxHtl/bZSDhKQigIf8zVWM2syZrnMfTq ri46vbr93Se5P1kTZTwB9ZmzWiEYpReGteFSXAA= X-Google-Smtp-Source: AHgI3Ib3bvPMPlfhS55kooOrkkuiC5H9FfwSQGd2XFxgxbFCXN4hLVGv7IGy4E3GbtRCRTfsYcfXY/IkOcfddT1R2IM= X-Received: by 2002:a25:1488:: with SMTP id 130mr2292136ybu.507.1550089402572; Wed, 13 Feb 2019 12:23:22 -0800 (PST) MIME-Version: 1.0 References: <20190213145443.26836-1-jack@suse.cz> <20190213145443.26836-3-jack@suse.cz> In-Reply-To: <20190213145443.26836-3-jack@suse.cz> From: Amir Goldstein Date: Wed, 13 Feb 2019 22:23:11 +0200 Message-ID: Subject: Re: [PATCH 2/6] fanotify: Move locking inside get_one_event() To: Jan Kara Cc: linux-fsdevel , Konstantin Khlebnikov , Vivek Trivedi , Orion Poplawski Content-Type: text/plain; charset="UTF-8" Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org On Wed, Feb 13, 2019 at 4:54 PM Jan Kara wrote: > > 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 Reviewed-by: Amir Goldstein > --- > 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 >