All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Kara <jack@suse.cz>
To: Miklos Szeredi <miklos@szeredi.hu>
Cc: Jan Kara <jack@suse.cz>,
	linux-fsdevel@vger.kernel.org,
	Amir Goldstein <amir73il@gmail.com>,
	Paul Moore <paul@paul-moore.com>
Subject: Re: [PATCH 20/33] fsnotify: Detach mark from object list when last reference is dropped
Date: Mon, 3 Apr 2017 12:04:06 +0200	[thread overview]
Message-ID: <20170403100406.GC15168@quack2.suse.cz> (raw)
In-Reply-To: <20170331154217.GC25833@veci.piliscsaba.szeredi.hu>

On Fri 31-03-17 17:42:17, Miklos Szeredi wrote:
> 
> On Tue, Mar 28, 2017 at 06:13:19PM +0200, Jan Kara wrote:
> > Instead of removing mark from object list from fsnotify_detach_mark(),
> > remove the mark when last reference to the mark is dropped. This will
> > allow fanotify to wait for userspace response to event without having to
> > hold onto fsnotify_mark_srcu.
> > 
> > To avoid pinning inodes by elevated refcount (and thus e.g. delaying
> > file deletion) while someone holds mark reference, we detach connector
> > from the object also from fsnotify_destroy_marks() and not only after
> > removing last mark from the list as it was now.
> > 
> > Reviewed-by: Amir Goldstein <amir73il@gmail.com>
> > Signed-off-by: Jan Kara <jack@suse.cz>
...
> > -static struct inode *fsnotify_detach_from_object(struct fsnotify_mark *mark)
> > +static struct inode *fsnotify_detach_connector_from_object(
> > +					struct fsnotify_mark_connector *conn)
> > +{
> > +	struct inode *inode = NULL;
> > +
> > +	if (conn->flags & FSNOTIFY_OBJ_TYPE_INODE) {
> > +		inode = conn->inode;
> > +		rcu_assign_pointer(inode->i_fsnotify_marks, NULL);
> > +		inode->i_fsnotify_mask = 0;
> > +		conn->inode = NULL;
> > +		conn->flags &= ~FSNOTIFY_OBJ_TYPE_INODE;
> > +	} else if (conn->flags & FSNOTIFY_OBJ_TYPE_VFSMOUNT) {
> > +		rcu_assign_pointer(real_mount(conn->mnt)->mnt_fsnotify_marks,
> > +				   NULL);
> > +		real_mount(conn->mnt)->mnt_fsnotify_mask = 0;
> > +		conn->mnt = NULL;
> > +		conn->flags &= ~FSNOTIFY_OBJ_TYPE_VFSMOUNT;
> > +	}
> > +
> > +	return inode;
> > +}
> 
> Could this helper been added in the previous patch where the code was
> introduced?

Yeah, possibly. I'll do that.

> > @@ -195,6 +221,9 @@ static struct inode *fsnotify_detach_from_object(struct fsnotify_mark *mark)
> >  	mark->connector = NULL;
> >  	spin_unlock(&conn->lock);
> >  
> > +	if (inode)
> > +		iput(inode);
> > +
> 
> iput() checks for non-NULL inode.

OK.

> > diff --git a/kernel/audit_tree.c b/kernel/audit_tree.c
> > index c0e494fd8eca..152400e8d077 100644
> > --- a/kernel/audit_tree.c
> > +++ b/kernel/audit_tree.c
> > @@ -172,27 +172,15 @@ static unsigned long inode_to_key(const struct inode *inode)
> >  /*
> >   * Function to return search key in our hash from chunk. Key 0 is special and
> >   * should never be present in the hash.
> > - *
> > - * Must be called with chunk->mark.lock held to protect from connector
> > - * becoming NULL.
> >   */
> > -static unsigned long __chunk_to_key(struct audit_chunk *chunk)
> > +static unsigned long chunk_to_key(struct audit_chunk *chunk)
> >  {
> > -	if (!chunk->mark.connector)
> > +	/* We have a reference to the mark so it should be attached. */
> > +	if (WARN_ON_ONCE(!chunk->mark.connector))
> >  		return 0;
> 
> Hmm, lifetime of mark previously:
> 
> - created but not attached (connector is NULL, no FSNOTIFY_MARK_FLAG_ATTACHED)
> - attached (connector is non-NULL, FSNOTIFY_MARK_FLAG_ATTACHED)
> - detached (connector is NULL, no FSNOTIFY_MARK_FLAG_ATTACHED)
> 
> The created, and attached states remain the same but detached now changed to:
> 
> - detached (connector is non-NULL, no FSNOTIFY_MARK_FLAG_ATTACHED)
> 
> Considering that, the warning seems right but the comment above not so.
> Maybe something like:
> 
>       /* We have a reference to the mark and it has been attached so we should
>          have a valid connector. */

Good point. The mark can be attached to group (that is what
FSNOTIFY_MARK_FLAG_ATTACHED reflects) and to connector which is what I was
speaking about in my comment. And I tend to mix these two in comments which
is confusing. I'll clarify.

> > @@ -202,7 +190,7 @@ static inline struct list_head *chunk_hash(unsigned long key)
> >  /* hash_lock & entry->lock is held by caller */
> >  static void insert_hash(struct audit_chunk *chunk)
> >  {
> > -	unsigned long key = __chunk_to_key(chunk);
> > +	unsigned long key = chunk_to_key(chunk);
> >  	struct list_head *list;
> >  
> >  	if (!key)
> > @@ -263,7 +251,7 @@ static void untag_chunk(struct node *p)
> >  
> >  	mutex_lock(&entry->group->mark_mutex);
> >  	spin_lock(&entry->lock);
> > -	if (chunk->dead || !entry->connector) {
> > +	if (chunk->dead || !entry->connector || !entry->connector->inode) {
> 
> So should we be testing FSNOTIFY_MARK_FLAG_ATTACHED instead?  Without
> understanding what audit is trying to do, that would be a lot more
> logical.  Or maybe there is a reason this is correct, it just needs an
> explanation.

That's an interesting idea. AFAIU checking FSNOTIFY_MARK_FLAG_ATTACHED
should be good and doing so would somewhat simplify the patches as well.
I'll try to do that.

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

  reply	other threads:[~2017-04-03 10:04 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-28 16:12 [PATCH 0/33 v6] fsnotify: Avoid SRCU stalls with fanotify permission events Jan Kara
2017-03-28 16:13 ` [PATCH 01/33] fsnotify: Remove unnecessary tests when showing fdinfo Jan Kara
2017-03-28 16:13 ` [PATCH 02/33] inotify: Remove inode pointers from debug messages Jan Kara
2017-03-28 16:13 ` [PATCH 03/33] fanotify: Move recalculation of inode / vfsmount mask under mark_mutex Jan Kara
2017-03-28 16:13 ` [PATCH 04/33] audit: Abstract hash key handling Jan Kara
2017-03-28 16:13 ` [PATCH 05/33] fsnotify: Update comments Jan Kara
2017-03-28 16:13 ` [PATCH 06/33] fsnotify: Move mark list head from object into dedicated structure Jan Kara
2017-03-28 16:13 ` [PATCH 07/33] fsnotify: Move object pointer to fsnotify_mark_connector Jan Kara
2017-03-28 16:13 ` [PATCH 08/33] fsnotify: Make fsnotify_mark_connector hold inode reference Jan Kara
2017-03-28 16:13 ` [PATCH 09/33] fsnotify: Remove indirection from mark list addition Jan Kara
2017-03-28 16:13 ` [PATCH 10/33] fsnotify: Move fsnotify_destroy_marks() Jan Kara
2017-03-28 16:13 ` [PATCH 11/33] fsnotify: Move locking into fsnotify_recalc_mask() Jan Kara
2017-03-28 16:13 ` [PATCH 12/33] fsnotify: Move locking into fsnotify_find_mark() Jan Kara
2017-03-28 16:13 ` [PATCH 13/33] fsnotify: Determine lock in fsnotify_destroy_marks() Jan Kara
2017-03-28 16:13 ` [PATCH 14/33] fsnotify: Remove indirection from fsnotify_detach_mark() Jan Kara
2017-03-29 15:29   ` Miklos Szeredi
2017-03-30  7:21     ` Jan Kara
2017-03-28 16:13 ` [PATCH 15/33] fsnotify: Remove useless list deletion and comment Jan Kara
2017-03-28 16:13 ` [PATCH 16/33] fsnotify: Lock object list with connector lock Jan Kara
2017-03-28 16:13 ` [PATCH 17/33] fsnotify: Free fsnotify_mark_connector when there is no mark attached Jan Kara
2017-03-30 10:02   ` Miklos Szeredi
2017-03-30 14:09     ` Jan Kara
2017-03-28 16:13 ` [PATCH 18/33] inotify: Do not drop mark reference under idr_lock Jan Kara
2017-03-28 16:13 ` [PATCH 19/33] fsnotify: Move queueing of mark for destruction into fsnotify_put_mark() Jan Kara
2017-03-28 16:13 ` [PATCH 20/33] fsnotify: Detach mark from object list when last reference is dropped Jan Kara
2017-03-31 15:42   ` Miklos Szeredi
2017-04-03 10:04     ` Jan Kara [this message]
2017-04-03 15:07       ` Jan Kara
2017-03-28 16:13 ` [PATCH 21/33] fsnotify: Remove special handling of mark destruction on group shutdown Jan Kara
2017-03-28 16:13 ` [PATCH 22/33] fsnotify: Provide framework for dropping SRCU lock in ->handle_event Jan Kara
2017-03-28 16:13 ` [PATCH 23/33] fsnotify: Pass fsnotify_iter_info into handle_event handler Jan Kara
2017-03-28 16:13 ` [PATCH 24/33] fanotify: Release SRCU lock when waiting for userspace response Jan Kara
2017-03-28 16:13 ` [PATCH 25/33] fsnotify: Remove fsnotify_set_mark_{,ignored_}mask_locked() Jan Kara
2017-03-28 16:13 ` [PATCH 26/33] fsnotify: Remove fsnotify_recalc_{inode|vfsmount}_mask() Jan Kara
2017-03-28 16:13 ` [PATCH 27/33] fsnotify: Inline fsnotify_clear_{inode|vfsmount}_mark_group() Jan Kara
2017-03-28 16:13 ` [PATCH 28/33] fsnotify: Rename fsnotify_clear_marks_by_group_flags() Jan Kara
2017-03-28 16:13 ` [PATCH 29/33] fsnotify: Remove fsnotify_detach_group_marks() Jan Kara
2017-03-28 16:13 ` [PATCH 30/33] fsnotify: Remove fsnotify_find_{inode|vfsmount}_mark() Jan Kara
2017-03-28 16:13 ` [PATCH 31/33] fsnotify: Drop inode_mark.c Jan Kara
2017-03-28 16:13 ` [PATCH 32/33] fsnotify: Add group pointer in fsnotify_init_mark() Jan Kara
2017-03-28 16:13 ` [PATCH 33/33] fsnotify: Move ->free_mark callback to fsnotify_ops Jan Kara
2017-04-03 13:19 ` [PATCH 0/33 v6] fsnotify: Avoid SRCU stalls with fanotify permission events Miklos Szeredi
2017-04-03 15:23   ` Jan Kara
  -- strict thread matches above, loose matches on Subject: below --
2017-03-15 10:45 [PATCH 0/33 v5] " Jan Kara
2017-03-15 10:46 ` [PATCH 20/33] fsnotify: Detach mark from object list when last reference is dropped 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=20170403100406.GC15168@quack2.suse.cz \
    --to=jack@suse.cz \
    --cc=amir73il@gmail.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=miklos@szeredi.hu \
    --cc=paul@paul-moore.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.