From: Miklos Szeredi <mszeredi@redhat.com>
To: linux-fsdevel@vger.kernel.org
Cc: Jan Kara <jack@suse.cz>, Amir Goldstein <amir73il@gmail.com>,
Xiong Zhou <xzhou@redhat.com>,
linux-kernel@vger.kernel.org
Subject: [PATCH v2 1/7] fsnotify: clean up fsnotify_prepare/finish_user_wait()
Date: Wed, 25 Oct 2017 10:41:33 +0200 [thread overview]
Message-ID: <1508920899-8115-2-git-send-email-mszeredi@redhat.com> (raw)
In-Reply-To: <1508920899-8115-1-git-send-email-mszeredi@redhat.com>
This patch doesn't actually fix any bug, just paves the way for fixing mark
and group pinning.
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
Cc: <stable@vger.kernel.org> # v4.12
---
fs/notify/mark.c | 89 ++++++++++++++++++++++++++------------------------------
1 file changed, 41 insertions(+), 48 deletions(-)
diff --git a/fs/notify/mark.c b/fs/notify/mark.c
index 9991f8826734..982527ce6a58 100644
--- a/fs/notify/mark.c
+++ b/fs/notify/mark.c
@@ -109,16 +109,6 @@ void fsnotify_get_mark(struct fsnotify_mark *mark)
atomic_inc(&mark->refcnt);
}
-/*
- * Get mark reference when we found the mark via lockless traversal of object
- * list. Mark can be already removed from the list by now and on its way to be
- * destroyed once SRCU period ends.
- */
-static bool fsnotify_get_mark_safe(struct fsnotify_mark *mark)
-{
- return atomic_inc_not_zero(&mark->refcnt);
-}
-
static void __fsnotify_recalc_mask(struct fsnotify_mark_connector *conn)
{
u32 new_mask = 0;
@@ -256,32 +246,56 @@ void fsnotify_put_mark(struct fsnotify_mark *mark)
FSNOTIFY_REAPER_DELAY);
}
-bool fsnotify_prepare_user_wait(struct fsnotify_iter_info *iter_info)
+/*
+ * Get mark reference when we found the mark via lockless traversal of object
+ * list. Mark can be already removed from the list by now and on its way to be
+ * destroyed once SRCU period ends.
+ */
+static bool fsnotify_get_mark_safe(struct fsnotify_mark *mark)
{
struct fsnotify_group *group;
- if (WARN_ON_ONCE(!iter_info->inode_mark && !iter_info->vfsmount_mark))
- return false;
-
- if (iter_info->inode_mark)
- group = iter_info->inode_mark->group;
- else
- group = iter_info->vfsmount_mark->group;
+ if (!mark)
+ return true;
+ group = mark->group;
/*
* Since acquisition of mark reference is an atomic op as well, we can
* be sure this inc is seen before any effect of refcount increment.
*/
atomic_inc(&group->user_waits);
+ if (atomic_inc_not_zero(&mark->refcnt))
+ return true;
+
+ if (atomic_dec_and_test(&group->user_waits) && group->shutdown)
+ wake_up(&group->notification_waitq);
- if (iter_info->inode_mark) {
- /* This can fail if mark is being removed */
- if (!fsnotify_get_mark_safe(iter_info->inode_mark))
- goto out_wait;
+ return false;
+}
+
+static void fsnotify_put_mark_wait(struct fsnotify_mark *mark)
+{
+ if (mark) {
+ struct fsnotify_group *group = mark->group;
+
+ fsnotify_put_mark(mark);
+ /*
+ * We abuse notification_waitq on group shutdown for waiting for
+ * all marks pinned when waiting for userspace.
+ */
+ if (atomic_dec_and_test(&group->user_waits) && group->shutdown)
+ wake_up(&group->notification_waitq);
}
- if (iter_info->vfsmount_mark) {
- if (!fsnotify_get_mark_safe(iter_info->vfsmount_mark))
- goto out_inode;
+}
+
+bool fsnotify_prepare_user_wait(struct fsnotify_iter_info *iter_info)
+{
+ /* This can fail if mark is being removed */
+ if (!fsnotify_get_mark_safe(iter_info->inode_mark))
+ return false;
+ if (!fsnotify_get_mark_safe(iter_info->vfsmount_mark)) {
+ fsnotify_put_mark_wait(iter_info->inode_mark);
+ return false;
}
/*
@@ -292,34 +306,13 @@ bool fsnotify_prepare_user_wait(struct fsnotify_iter_info *iter_info)
srcu_read_unlock(&fsnotify_mark_srcu, iter_info->srcu_idx);
return true;
-out_inode:
- if (iter_info->inode_mark)
- fsnotify_put_mark(iter_info->inode_mark);
-out_wait:
- if (atomic_dec_and_test(&group->user_waits) && group->shutdown)
- wake_up(&group->notification_waitq);
- return false;
}
void fsnotify_finish_user_wait(struct fsnotify_iter_info *iter_info)
{
- struct fsnotify_group *group = NULL;
-
iter_info->srcu_idx = srcu_read_lock(&fsnotify_mark_srcu);
- if (iter_info->inode_mark) {
- group = iter_info->inode_mark->group;
- fsnotify_put_mark(iter_info->inode_mark);
- }
- if (iter_info->vfsmount_mark) {
- group = iter_info->vfsmount_mark->group;
- fsnotify_put_mark(iter_info->vfsmount_mark);
- }
- /*
- * We abuse notification_waitq on group shutdown for waiting for all
- * marks pinned when waiting for userspace.
- */
- if (atomic_dec_and_test(&group->user_waits) && group->shutdown)
- wake_up(&group->notification_waitq);
+ fsnotify_put_mark_wait(iter_info->inode_mark);
+ fsnotify_put_mark_wait(iter_info->vfsmount_mark);
}
/*
--
2.5.5
next prev parent reply other threads:[~2017-10-25 8:43 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-25 8:41 [PATCH v2 0/7] fix fanotify issues with the series in v4.12 Miklos Szeredi
2017-10-25 8:41 ` Miklos Szeredi [this message]
2017-10-25 12:06 ` [PATCH v2 1/7] fsnotify: clean up fsnotify_prepare/finish_user_wait() Amir Goldstein
2017-10-25 12:07 ` Amir Goldstein
2017-10-25 14:15 ` Miklos Szeredi
2017-10-25 8:41 ` [PATCH v2 2/7] fsnotify: pin both inode and vfsmount mark Miklos Szeredi
2017-10-30 13:34 ` Jan Kara
2017-10-30 13:42 ` Miklos Szeredi
2017-10-30 14:05 ` Jan Kara
2017-10-25 8:41 ` [PATCH v2 3/7] fsnotify: fix pinning group in fsnotify_prepare_user_wait() Miklos Szeredi
2017-10-25 8:41 ` [PATCH v2 4/7] fsnotify: skip unattached marks Miklos Szeredi
2017-10-30 14:00 ` Jan Kara
2017-10-30 14:27 ` Miklos Szeredi
2017-10-25 8:41 ` [PATCH v2 5/7] fanotify: fix fsnotify_prepare_user_wait() failure Miklos Szeredi
2017-10-25 8:41 ` [PATCH v2 6/7] fsnotify: clean up fsnotify() Miklos Szeredi
2017-10-25 11:46 ` Amir Goldstein
2017-10-25 8:41 ` [PATCH v2 7/7] fanotify: clean up CONFIG_FANOTIFY_ACCESS_PERMISSIONS ifdefs Miklos Szeredi
2017-10-25 11:44 ` Amir Goldstein
2017-10-25 14:19 ` Miklos Szeredi
2017-10-30 17:20 ` Jan Kara
2017-10-25 14:31 ` [PATCH v2 0/7] fix fanotify issues with the series in v4.12 Miklos Szeredi
2017-10-25 15:13 ` Amir Goldstein
2017-10-27 11:53 ` Jan Kara
2017-10-30 15:56 ` Miklos Szeredi
2017-10-30 17:27 ` Jan Kara
2017-10-30 20:18 ` Miklos Szeredi
2017-10-31 9:54 ` Jan Kara
2017-10-31 11:02 ` Amir Goldstein
2017-10-31 16:27 ` Jan Kara
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1508920899-8115-2-git-send-email-mszeredi@redhat.com \
--to=mszeredi@redhat.com \
--cc=amir73il@gmail.com \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=xzhou@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).