From: Josef Bacik <josef@toxicpanda.com>
To: Amir Goldstein <amir73il@gmail.com>
Cc: kernel-team@fb.com, linux-fsdevel@vger.kernel.org, jack@suse.cz,
brauner@kernel.org, linux-xfs@vger.kernel.org,
gfs2@lists.linux.dev, linux-bcachefs@vger.kernel.org
Subject: Re: [PATCH v2 13/16] fsnotify: generate pre-content permission event on page fault
Date: Fri, 9 Aug 2024 10:19:07 -0400 [thread overview]
Message-ID: <20240809141907.GD645452@perftesting> (raw)
In-Reply-To: <CAOQ4uxivX+mxfpOUTAsxHVoCGb9YHdi-qHswN9O4EJ53sKUVfw@mail.gmail.com>
On Fri, Aug 09, 2024 at 12:34:34PM +0200, Amir Goldstein wrote:
> On Thu, Aug 8, 2024 at 9:28 PM Josef Bacik <josef@toxicpanda.com> 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.
> >
> > Signed-off-by: Josef Bacik <josef@toxicpanda.com>
> > ---
> > include/linux/mm.h | 2 +
> > mm/filemap.c | 97 ++++++++++++++++++++++++++++++++++++++++++----
> > 2 files changed, 92 insertions(+), 7 deletions(-)
> >
> > diff --git a/include/linux/mm.h b/include/linux/mm.h
> > index ab3d78116043..c33f3b7f7261 100644
> > --- a/include/linux/mm.h
> > +++ b/include/linux/mm.h
> > @@ -3503,6 +3503,8 @@ extern vm_fault_t filemap_fault(struct vm_fault *vmf);
> > extern vm_fault_t filemap_map_pages(struct vm_fault *vmf,
> > pgoff_t start_pgoff, pgoff_t end_pgoff);
> > extern vm_fault_t filemap_page_mkwrite(struct vm_fault *vmf);
> > +extern vm_fault_t filemap_maybe_emit_fsnotify_event(struct vm_fault *vmf,
> > + struct file **fpin);
> >
> > extern unsigned long stack_guard_gap;
> > /* Generic expand stack which grows the stack according to GROWS{UP,DOWN} */
> > diff --git a/mm/filemap.c b/mm/filemap.c
> > index 8b1684b62177..3d232166b051 100644
> > --- a/mm/filemap.c
> > +++ b/mm/filemap.c
> > @@ -46,6 +46,7 @@
> > #include <linux/pipe_fs_i.h>
> > #include <linux/splice.h>
> > #include <linux/rcupdate_wait.h>
> > +#include <linux/fsnotify.h>
> > #include <asm/pgalloc.h>
> > #include <asm/tlbflush.h>
> > #include "internal.h"
> > @@ -3112,13 +3113,13 @@ static int lock_folio_maybe_drop_mmap(struct vm_fault *vmf, struct folio *folio,
> > * that. If we didn't pin a file then we return NULL. The file that is
> > * returned needs to be fput()'ed when we're done with it.
> > */
> > -static struct file *do_sync_mmap_readahead(struct vm_fault *vmf)
> > +static struct file *do_sync_mmap_readahead(struct vm_fault *vmf,
> > + struct file *fpin)
> > {
> > struct file *file = vmf->vma->vm_file;
> > struct file_ra_state *ra = &file->f_ra;
> > struct address_space *mapping = file->f_mapping;
> > DEFINE_READAHEAD(ractl, file, ra, mapping, vmf->pgoff);
> > - struct file *fpin = NULL;
> > unsigned long vm_flags = vmf->vma->vm_flags;
> > unsigned int mmap_miss;
> >
> > @@ -3190,12 +3191,12 @@ static struct file *do_sync_mmap_readahead(struct vm_fault *vmf)
> > * was pinned if we have to drop the mmap_lock in order to do IO.
> > */
> > static struct file *do_async_mmap_readahead(struct vm_fault *vmf,
> > - struct folio *folio)
> > + struct folio *folio,
> > + struct file *fpin)
> > {
> > struct file *file = vmf->vma->vm_file;
> > struct file_ra_state *ra = &file->f_ra;
> > DEFINE_READAHEAD(ractl, file, ra, file->f_mapping, vmf->pgoff);
> > - struct file *fpin = NULL;
> > unsigned int mmap_miss;
> >
> > /* See comment in do_sync_mmap_readahead. */
> > @@ -3260,6 +3261,72 @@ static vm_fault_t filemap_fault_recheck_pte_none(struct vm_fault *vmf)
> > return ret;
> > }
> >
> > +/**
> > + * filemap_maybe_emit_fsnotify_event - maybe emit a pre-content event.
> > + * @vmf: struct vm_fault containing details of the fault.
> > + * @fpin: pointer to the struct file pointer that may be pinned.
> > + *
> > + * If we have pre-content watches on this file we will need to emit an event for
> > + * this range. We will handle dropping the lock and emitting the event.
> > + *
> > + * If FAULT_FLAG_RETRY_NOWAIT is set then we'll return VM_FAULT_RETRY.
> > + *
> > + * If no event was emitted then *fpin will be NULL and we will return 0.
> > + *
> > + * If any error occurred we will return VM_FAULT_SIGBUS, *fpin could still be
> > + * set and will need to have fput() called on it.
> > + *
> > + * If we emitted the event then we will return 0 and *fpin will be set, this
> > + * must have fput() called on it, and the caller must call VM_FAULT_RETRY after
> > + * any other operations it does in order to re-fault the page and make sure the
> > + * appropriate locking is maintained.
> > + *
> > + * Return: the appropriate vm_fault_t return code, 0 on success.
> > + */
> > +vm_fault_t filemap_maybe_emit_fsnotify_event(struct vm_fault *vmf,
> > + struct file **fpin)
> > +{
> > + struct file *file = vmf->vma->vm_file;
> > + loff_t pos = vmf->pgoff << PAGE_SHIFT;
> > + int mask = (vmf->flags & FAULT_FLAG_WRITE) ? MAY_WRITE : MAY_READ;
>
> You missed my comment about using MAY_ACCESS here
> and alter fsnotify hook, so legacy FAN_ACCESS_PERM event
> won't be generated from page fault.
I did miss that, I'll fix it up in v3, thanks!
Josef
next prev parent reply other threads:[~2024-08-09 14:19 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-08 19:27 [PATCH v2 00/16] fanotify: add pre-content hooks Josef Bacik
2024-08-08 19:27 ` [PATCH v2 01/16] fanotify: don't skip extra event info if no info_mode is set Josef Bacik
2024-08-08 19:27 ` [PATCH v2 02/16] fsnotify: introduce pre-content permission event Josef Bacik
2024-08-08 19:27 ` [PATCH v2 03/16] fsnotify: generate pre-content permission event on open Josef Bacik
2024-08-09 11:51 ` Christian Brauner
2024-08-08 19:27 ` [PATCH v2 04/16] fanotify: introduce FAN_PRE_ACCESS permission event Josef Bacik
2024-08-09 11:57 ` Christian Brauner
2024-08-08 19:27 ` [PATCH v2 05/16] fanotify: introduce FAN_PRE_MODIFY " Josef Bacik
2024-08-09 11:57 ` Christian Brauner
2024-08-08 19:27 ` [PATCH v2 06/16] fanotify: pass optional file access range in pre-content event Josef Bacik
2024-08-09 12:00 ` Christian Brauner
2024-08-09 18:36 ` Josef Bacik
2024-08-08 19:27 ` [PATCH v2 07/16] fanotify: rename a misnamed constant Josef Bacik
2024-08-09 11:41 ` Christian Brauner
2024-08-08 19:27 ` [PATCH v2 08/16] fanotify: report file range info with pre-content events Josef Bacik
2024-08-08 19:27 ` [PATCH v2 09/16] fanotify: allow to set errno in FAN_DENY permission response Josef Bacik
2024-08-09 12:06 ` Christian Brauner
2024-08-09 18:38 ` Josef Bacik
2024-08-08 19:27 ` [PATCH v2 10/16] fanotify: add a helper to check for pre content events Josef Bacik
2024-08-09 12:10 ` Christian Brauner
2024-08-08 19:27 ` [PATCH v2 11/16] fanotify: disable readahead if we have pre-content watches Josef Bacik
2024-08-09 12:12 ` Christian Brauner
2024-08-08 19:27 ` [PATCH v2 12/16] mm: don't allow huge faults for files with pre content watches Josef Bacik
2024-08-09 12:13 ` Christian Brauner
2024-08-08 19:27 ` [PATCH v2 13/16] fsnotify: generate pre-content permission event on page fault Josef Bacik
2024-08-09 10:34 ` Amir Goldstein
2024-08-09 14:19 ` Josef Bacik [this message]
2024-08-08 19:27 ` [PATCH v2 14/16] bcachefs: add pre-content fsnotify hook to fault Josef Bacik
2024-08-09 13:11 ` Amir Goldstein
2024-08-09 14:21 ` Josef Bacik
2024-08-08 19:27 ` [PATCH v2 15/16] gfs2: " Josef Bacik
2024-08-08 19:27 ` [PATCH v2 16/16] xfs: add pre-content fsnotify hook for write faults Josef Bacik
2024-08-08 22:03 ` Dave Chinner
2024-08-09 14:15 ` Josef Bacik
2024-08-08 22:15 ` [PATCH v2 00/16] fanotify: add pre-content hooks Dave Chinner
2024-08-09 14:18 ` Josef Bacik
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=20240809141907.GD645452@perftesting \
--to=josef@toxicpanda.com \
--cc=amir73il@gmail.com \
--cc=brauner@kernel.org \
--cc=gfs2@lists.linux.dev \
--cc=jack@suse.cz \
--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 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.