All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Kara <jack@suse.cz>
To: Gabriel Krisman Bertazi <krisman@collabora.com>
Cc: jack@suse.com, amir73il@gmail.com, djwong@kernel.org,
	tytso@mit.edu, david@fromorbit.com, dhowells@redhat.com,
	khazhy@google.com, linux-fsdevel@vger.kernel.org,
	linux-ext4@vger.kernel.org, linux-api@vger.kernel.org,
	kernel@collabora.com
Subject: Re: [PATCH v5 19/23] fanotify: Report fid info for file related file system errors
Date: Thu, 5 Aug 2021 13:28:41 +0200	[thread overview]
Message-ID: <20210805112841.GJ14483@quack2.suse.cz> (raw)
In-Reply-To: <20210804160612.3575505-20-krisman@collabora.com>

On Wed 04-08-21 12:06:08, Gabriel Krisman Bertazi wrote:
> Plumb the pieces to add a FID report to error records.  Since all error
> event memory must be pre-allocated, we estimate a file handler size and
> if it is insuficient, we report an invalid FID and increase the
> prediction for the next error slot allocation.

Hum, cannot we just preallocate MAX_HANDLE_SZ? It is wasteful but then I
don't expect error marks would be that frequent for this to really
matter and the code would be simpler.

								Honza

> 
> For errors that don't expose a file handler report it with an invalid
> FID.
> 
> Signed-off-by: Gabriel Krisman Bertazi <krisman@collabora.com>
> ---
>  fs/notify/fanotify/fanotify.c      | 27 +++++++++++++++++++++++++++
>  fs/notify/fanotify/fanotify.h      | 12 ++++++++++++
>  fs/notify/fanotify/fanotify_user.c | 19 ++++++++++++++++++-
>  3 files changed, 57 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c
> index 4e9e271a4394..2fd30b5eb9d3 100644
> --- a/fs/notify/fanotify/fanotify.c
> +++ b/fs/notify/fanotify/fanotify.c
> @@ -705,7 +705,9 @@ static void fanotify_insert_error_event(struct fsnotify_group *group,
>  {
>  	const struct fs_error_report *report = (struct fs_error_report *) data;
>  	struct fanotify_event *fae = FANOTIFY_E(event);
> +	struct inode *inode = report->inode;
>  	struct fanotify_error_event *fee;
> +	int fh_len;
>  
>  	/* This might be an unexpected type of event (i.e. overflow). */
>  	if (!fanotify_is_error_event(fae->mask))
> @@ -715,6 +717,31 @@ static void fanotify_insert_error_event(struct fsnotify_group *group,
>  	fee->fae.type = FANOTIFY_EVENT_TYPE_FS_ERROR;
>  	fee->error = report->error;
>  	fee->err_count = 1;
> +	fee->fsid = fee->sb_mark->fsn_mark.connector->fsid;
> +
> +	/*
> +	 * Error reporting needs to happen in atomic context.  If this
> +	 * inode's file handler length is more than we initially
> +	 * predicted, there is nothing better we can do than report the
> +	 * error with a bad file handler.
> +	 */
> +	fh_len = fanotify_encode_fh_len(inode);
> +	if (fh_len > fee->sb_mark->pred_fh_len) {
> +		pr_warn_ratelimited(
> +			"FH overflows error event. Drop inode information.\n");
> +		/*
> +		 * Update the handler size prediction for the next error
> +		 * event allocation.  This reduces the chance of another
> +		 * overflow.
> +		 */
> +		fee->sb_mark->pred_fh_len = fh_len;
> +
> +		/* For the current error, ignore the inode information. */
> +		inode = NULL;
> +		fh_len = fanotify_encode_fh_len(NULL);
> +	}
> +
> +	fanotify_encode_fh(&fee->object_fh, inode, fh_len, NULL, 0);
>  }
>  
>  /*
> diff --git a/fs/notify/fanotify/fanotify.h b/fs/notify/fanotify/fanotify.h
> index 8929ea50f96f..e4e7968b70ee 100644
> --- a/fs/notify/fanotify/fanotify.h
> +++ b/fs/notify/fanotify/fanotify.h
> @@ -142,6 +142,7 @@ FANOTIFY_MARK_FLAG(SB_MARK);
>  
>  struct fanotify_sb_mark {
>  	struct fsnotify_mark fsn_mark;
> +	size_t pred_fh_len;
>  	struct fanotify_error_event *fee_slot;
>  };
>  
> @@ -227,6 +228,13 @@ struct fanotify_error_event {
>  	u32 err_count; /* Suppressed errors count */
>  
>  	struct fanotify_sb_mark *sb_mark; /* Back reference to the mark. */
> +
> +	__kernel_fsid_t fsid; /* FSID this error refers to. */
> +	/*
> +	 * object_fh is followed by a variable sized buffer, so it must
> +	 * be the last element of this structure.
> +	 */
> +	struct fanotify_fh object_fh;
>  };
>  
>  static inline struct fanotify_error_event *
> @@ -241,6 +249,8 @@ static inline __kernel_fsid_t *fanotify_event_fsid(struct fanotify_event *event)
>  		return &FANOTIFY_FE(event)->fsid;
>  	else if (event->type == FANOTIFY_EVENT_TYPE_FID_NAME)
>  		return &FANOTIFY_NE(event)->fsid;
> +	else if (event->type == FANOTIFY_EVENT_TYPE_FS_ERROR)
> +		return &FANOTIFY_EE(event)->fsid;
>  	else
>  		return NULL;
>  }
> @@ -252,6 +262,8 @@ static inline struct fanotify_fh *fanotify_event_object_fh(
>  		return &FANOTIFY_FE(event)->object_fh;
>  	else if (event->type == FANOTIFY_EVENT_TYPE_FID_NAME)
>  		return fanotify_info_file_fh(&FANOTIFY_NE(event)->info);
> +	else if (event->type == FANOTIFY_EVENT_TYPE_FS_ERROR)
> +		return &FANOTIFY_EE(event)->object_fh;
>  	else
>  		return NULL;
>  }
> diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
> index e7fe6bc61b6f..74def82630bb 100644
> --- a/fs/notify/fanotify/fanotify_user.c
> +++ b/fs/notify/fanotify/fanotify_user.c
> @@ -172,8 +172,25 @@ static struct fanotify_error_event *fanotify_alloc_error_event(
>  
>  {
>  	struct fanotify_error_event *fee;
> +	struct super_block *sb;
>  
> -	fee = kzalloc(sizeof(*fee), GFP_KERNEL_ACCOUNT);
> +	if (!sb_mark->pred_fh_len) {
> +		/*
> +		 * The handler size is initially predicted to be the
> +		 * same size as the root inode file handler.  It can be
> +		 * increased later if a larger file handler is found.
> +		 */
> +		sb = container_of(sb_mark->fsn_mark.connector->obj,
> +				  struct super_block, s_fsnotify_marks);
> +		sb_mark->pred_fh_len =
> +			fanotify_encode_fh_len(sb->s_root->d_inode);
> +	}
> +
> +	/* Guarantee there is always space to report an invalid FID. */
> +	if (sb_mark->pred_fh_len < FANOTIFY_NULL_FH_LEN)
> +		sb_mark->pred_fh_len = FANOTIFY_NULL_FH_LEN;
> +
> +	fee = kzalloc(sizeof(*fee) + sb_mark->pred_fh_len, GFP_KERNEL_ACCOUNT);
>  	if (!fee)
>  		return NULL;
>  
> -- 
> 2.32.0
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

  reply	other threads:[~2021-08-05 11:28 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-04 16:05 [PATCH v5 00/23] File system wide monitoring Gabriel Krisman Bertazi
2021-08-04 16:05 ` [PATCH v5 01/23] fsnotify: Don't insert unmergeable events in hashtable Gabriel Krisman Bertazi
2021-08-04 16:05 ` [PATCH v5 02/23] fanotify: Fold event size calculation to its own function Gabriel Krisman Bertazi
2021-08-04 16:05 ` [PATCH v5 03/23] fanotify: Split fsid check from other fid mode checks Gabriel Krisman Bertazi
2021-08-04 16:05 ` [PATCH v5 04/23] fsnotify: Reserve mark bits for backends Gabriel Krisman Bertazi
2021-08-05  8:44   ` kernel test robot
2021-08-05  8:44     ` kernel test robot
2021-08-05  9:14   ` Jan Kara
2021-08-04 16:05 ` [PATCH v5 05/23] fanotify: Split superblock marks out to a new cache Gabriel Krisman Bertazi
2021-08-05  9:24   ` Jan Kara
2021-08-04 16:05 ` [PATCH v5 06/23] inotify: Don't force FS_IN_IGNORED Gabriel Krisman Bertazi
2021-08-04 16:05 ` [PATCH v5 07/23] fsnotify: Add helper to detect overflow_event Gabriel Krisman Bertazi
2021-08-04 16:05 ` [PATCH v5 08/23] fsnotify: Add wrapper around fsnotify_add_event Gabriel Krisman Bertazi
2021-08-05  9:28   ` Jan Kara
2021-08-04 16:05 ` [PATCH v5 09/23] fsnotify: Support passing argument to insert callback on add_event Gabriel Krisman Bertazi
2021-08-04 16:05 ` [PATCH v5 10/23] fsnotify: Allow events reported with an empty inode Gabriel Krisman Bertazi
2021-08-05 10:24   ` Jan Kara
2021-08-05 14:14     ` Amir Goldstein
2021-08-05 15:55       ` Jan Kara
2021-08-04 16:06 ` [PATCH v5 11/23] fsnotify: Support FS_ERROR event type Gabriel Krisman Bertazi
2021-08-04 16:06 ` [PATCH v5 12/23] fanotify: Expose helper to estimate file handle encoding length Gabriel Krisman Bertazi
2021-08-04 16:06 ` [PATCH v5 13/23] fanotify: Allow file handle encoding for unhashed events Gabriel Krisman Bertazi
2021-08-05  9:39   ` Jan Kara
2021-08-04 16:06 ` [PATCH v5 14/23] fanotify: Encode invalid file handler when no inode is provided Gabriel Krisman Bertazi
2021-08-05  9:56   ` Jan Kara
2021-08-11 21:12     ` Gabriel Krisman Bertazi
2021-08-12 14:20       ` Jan Kara
2021-08-12 15:14         ` Gabriel Krisman Bertazi
2021-08-12 15:50           ` Amir Goldstein
2021-08-12 15:17         ` Amir Goldstein
2021-08-13 12:09           ` Jan Kara
2021-08-13 17:25             ` Amir Goldstein
2021-08-04 16:06 ` [PATCH v5 15/23] fanotify: Require fid_mode for any non-fd event Gabriel Krisman Bertazi
2021-08-05 10:29   ` Jan Kara
2021-08-04 16:06 ` [PATCH v5 16/23] fanotify: Reserve UAPI bits for FAN_FS_ERROR Gabriel Krisman Bertazi
2021-08-05 10:33   ` Jan Kara
2021-08-04 16:06 ` [PATCH v5 17/23] fanotify: Preallocate per superblock mark error event Gabriel Krisman Bertazi
2021-08-04 16:06 ` [PATCH v5 18/23] fanotify: Handle FAN_FS_ERROR events Gabriel Krisman Bertazi
2021-08-05 12:15   ` Jan Kara
2021-08-05 13:50     ` Amir Goldstein
2021-08-10  1:35     ` Gabriel Krisman Bertazi
2021-08-04 16:06 ` [PATCH v5 19/23] fanotify: Report fid info for file related file system errors Gabriel Krisman Bertazi
2021-08-05 11:28   ` Jan Kara [this message]
2021-08-05 12:06   ` Jan Kara
2021-08-04 16:06 ` [PATCH v5 20/23] fanotify: Emit generic error info type for error event Gabriel Krisman Bertazi
2021-08-04 16:06 ` [PATCH v5 21/23] ext4: Send notifications on error Gabriel Krisman Bertazi
2021-08-04 16:06 ` [PATCH v5 22/23] samples: Add fs error monitoring example Gabriel Krisman Bertazi
2021-08-04 16:06 ` [PATCH v5 23/23] docs: Document the FAN_FS_ERROR event Gabriel Krisman Bertazi

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=20210805112841.GJ14483@quack2.suse.cz \
    --to=jack@suse.cz \
    --cc=amir73il@gmail.com \
    --cc=david@fromorbit.com \
    --cc=dhowells@redhat.com \
    --cc=djwong@kernel.org \
    --cc=jack@suse.com \
    --cc=kernel@collabora.com \
    --cc=khazhy@google.com \
    --cc=krisman@collabora.com \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=tytso@mit.edu \
    /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.