public inbox for linux-bcachefs@vger.kernel.org
 help / color / mirror / Atom feed
From: Dave Chinner <david@fromorbit.com>
To: Josef Bacik <josef@toxicpanda.com>
Cc: kernel-team@fb.com, linux-fsdevel@vger.kernel.org, jack@suse.cz,
	amir73il@gmail.com, brauner@kernel.org,
	linux-xfs@vger.kernel.org, gfs2@lists.linux.dev,
	linux-bcachefs@vger.kernel.org
Subject: Re: [PATCH v3 13/16] fsnotify: generate pre-content permission event on page fault
Date: Sat, 10 Aug 2024 09:05:40 +1000	[thread overview]
Message-ID: <ZragxG7wkTsD1sdy@dread.disaster.area> (raw)
In-Reply-To: <192b90df727e968ca3a17b6b128c10f3575bf6a3.1723228772.git.josef@toxicpanda.com>

On Fri, Aug 09, 2024 at 02:44:21PM -0400, Josef Bacik wrote:
> FS_PRE_ACCESS or FS_PRE_MODIFY will be generated on page fault depending
> on the faulting method.
> 
> This pre-content event is meant to be used by hierarchical storage
> managers that want to fill in the file content on first read access.
> 
> Export a simple helper that file systems that have their own ->fault()
> will use, and have a more complicated helper to be do fancy things with
> in filemap_fault.
> 
> Signed-off-by: Josef Bacik <josef@toxicpanda.com>

....
> +/**
> + * filemap_maybe_emit_fsnotify_event - maybe emit a pre-content event.
> + * @vmf:	struct vm_fault containing details of the fault.
> + *
> + * If we have a pre-content watch on this file we will emit an event for this
> + * range.  If we return anything the fault caller should return immediately, we
> + * will return VM_FAULT_RETRY if we had to emit an event, which will trigger the
> + * fault again and then the fault handler will run the second time through.
> + *
> + * Return: a bitwise-OR of %VM_FAULT_ codes, 0 if nothing happened.
> + */
> +vm_fault_t filemap_maybe_emit_fsnotify_event(struct vm_fault *vmf)
> +{
> +	struct file *fpin = NULL;
> +	vm_fault_t ret;
> +
> +	ret = __filemap_maybe_emit_fsnotify_event(vmf, &fpin);
> +	if (ret) {
> +		if (fpin)
> +			fput(fpin);
> +		return ret;
> +	} else if (fpin) {
> +		fput(fpin);
> +		return VM_FAULT_RETRY;
> +	}

Logic is back to front.  Both paths have to check for fpin,
only one fpin path needs to modify ret:

	ret = __filemap_maybe_emit_fsnotify_event(vmf, &fpin);
	if (fpin) {
		fput(fpin);
		if (!ret)
			ret = VM_FAULT_RETRY;
	}
	return ret;

> +
> +	return 0;
> +}
> +EXPORT_SYMBOL_GPL(filemap_maybe_emit_fsnotify_event);
> +
>  /**
>   * filemap_fault - read in file data for page fault handling
>   * @vmf:	struct vm_fault containing details of the fault
> @@ -3299,6 +3391,19 @@ vm_fault_t filemap_fault(struct vm_fault *vmf)
>  	if (unlikely(index >= max_idx))
>  		return VM_FAULT_SIGBUS;
>  
> +	/*
> +	 * If we have pre-content watchers then we need to generate events on
> +	 * page fault so that we can populate any data before the fault.
> +	 */
> +	ret = __filemap_maybe_emit_fsnotify_event(vmf, &fpin);
> +	if (unlikely(ret)) {
> +		if (fpin) {
> +			fput(fpin);
> +			ret |= VM_FAULT_RETRY;
> +		}
> +		return ret;
> +	}

Why do we or in VM_FAULT_RETRY here where as the previous case we
simply return VM_FAULT_RETRY? Which one of these is wrong? If both
are correct, then a comment explaining this is in order...

-Dave.
-- 
Dave Chinner
david@fromorbit.com

  reply	other threads:[~2024-08-09 23:05 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-09 18:44 [PATCH v3 00/16] fanotify: add pre-content hooks Josef Bacik
2024-08-09 18:44 ` [PATCH v3 01/16] fanotify: don't skip extra event info if no info_mode is set Josef Bacik
2024-08-09 18:44 ` [PATCH v3 02/16] fsnotify: introduce pre-content permission event Josef Bacik
2024-08-09 18:44 ` [PATCH v3 03/16] fsnotify: generate pre-content permission event on open Josef Bacik
2024-08-09 18:44 ` [PATCH v3 04/16] fanotify: introduce FAN_PRE_ACCESS permission event Josef Bacik
2024-08-09 18:44 ` [PATCH v3 05/16] fanotify: introduce FAN_PRE_MODIFY " Josef Bacik
2024-08-09 18:44 ` [PATCH v3 06/16] fanotify: pass optional file access range in pre-content event Josef Bacik
2024-08-09 18:44 ` [PATCH v3 07/16] fanotify: rename a misnamed constant Josef Bacik
2024-08-09 18:44 ` [PATCH v3 08/16] fanotify: report file range info with pre-content events Josef Bacik
2024-08-09 18:44 ` [PATCH v3 09/16] fanotify: allow to set errno in FAN_DENY permission response Josef Bacik
2024-08-09 18:44 ` [PATCH v3 10/16] fanotify: add a helper to check for pre content events Josef Bacik
2024-08-09 18:44 ` [PATCH v3 11/16] fanotify: disable readahead if we have pre-content watches Josef Bacik
2024-08-09 18:44 ` [PATCH v3 12/16] mm: don't allow huge faults for files with pre content watches Josef Bacik
2024-08-09 18:44 ` [PATCH v3 13/16] fsnotify: generate pre-content permission event on page fault Josef Bacik
2024-08-09 23:05   ` Dave Chinner [this message]
2024-08-09 18:44 ` [PATCH v3 14/16] bcachefs: add pre-content fsnotify hook to fault Josef Bacik
2024-08-10 20:06   ` Kent Overstreet
2024-08-09 18:44 ` [PATCH v3 15/16] gfs2: " Josef Bacik
2024-08-09 18:44 ` [PATCH v3 16/16] xfs: add pre-content fsnotify hook for write faults Josef Bacik
2024-08-09 23:06   ` Dave Chinner
2024-08-11  8:40   ` Christoph Hellwig

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=ZragxG7wkTsD1sdy@dread.disaster.area \
    --to=david@fromorbit.com \
    --cc=amir73il@gmail.com \
    --cc=brauner@kernel.org \
    --cc=gfs2@lists.linux.dev \
    --cc=jack@suse.cz \
    --cc=josef@toxicpanda.com \
    --cc=kernel-team@fb.com \
    --cc=linux-bcachefs@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-xfs@vger.kernel.org \
    /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