linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mike Rapoport <rppt@kernel.org>
To: Lokesh Gidra <lokeshgidra@google.com>
Cc: akpm@linux-foundation.org, linux-fsdevel@vger.kernel.org,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	selinux@vger.kernel.org, surenb@google.com,
	kernel-team@android.com, aarcange@redhat.com, peterx@redhat.com,
	david@redhat.com, axelrasmussen@google.com, bgeffon@google.com,
	willy@infradead.org, jannh@google.com, kaleshsingh@google.com,
	ngeoffray@google.com, timmurray@google.com
Subject: Re: [PATCH v2 1/3] userfaultfd: move userfaultfd_ctx struct to header file
Date: Tue, 30 Jan 2024 09:12:44 +0200	[thread overview]
Message-ID: <ZbihbPMZO2gT7mB4@kernel.org> (raw)
In-Reply-To: <20240129193512.123145-2-lokeshgidra@google.com>

On Mon, Jan 29, 2024 at 11:35:10AM -0800, Lokesh Gidra wrote:
> Moving the struct to userfaultfd_k.h to be accessible from
> mm/userfaultfd.c. There are no other changes in the struct.

Just a thought, it maybe worth to move all of fs/userfaultfd.c to
mm/userfaultfd.c ...
 
> This is required to prepare for using per-vma locks in userfaultfd
> operations.
> 
> Signed-off-by: Lokesh Gidra <lokeshgidra@google.com>

Reviewed-by: Mike Rapoport (IBM) <rppt@kernel.org>

> ---
>  fs/userfaultfd.c              | 39 -----------------------------------
>  include/linux/userfaultfd_k.h | 39 +++++++++++++++++++++++++++++++++++
>  2 files changed, 39 insertions(+), 39 deletions(-)
> 
> diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c
> index 05c8e8a05427..58331b83d648 100644
> --- a/fs/userfaultfd.c
> +++ b/fs/userfaultfd.c
> @@ -50,45 +50,6 @@ static struct ctl_table vm_userfaultfd_table[] = {
>  
>  static struct kmem_cache *userfaultfd_ctx_cachep __ro_after_init;
>  
> -/*
> - * Start with fault_pending_wqh and fault_wqh so they're more likely
> - * to be in the same cacheline.
> - *
> - * Locking order:
> - *	fd_wqh.lock
> - *		fault_pending_wqh.lock
> - *			fault_wqh.lock
> - *		event_wqh.lock
> - *
> - * To avoid deadlocks, IRQs must be disabled when taking any of the above locks,
> - * since fd_wqh.lock is taken by aio_poll() while it's holding a lock that's
> - * also taken in IRQ context.
> - */
> -struct userfaultfd_ctx {
> -	/* waitqueue head for the pending (i.e. not read) userfaults */
> -	wait_queue_head_t fault_pending_wqh;
> -	/* waitqueue head for the userfaults */
> -	wait_queue_head_t fault_wqh;
> -	/* waitqueue head for the pseudo fd to wakeup poll/read */
> -	wait_queue_head_t fd_wqh;
> -	/* waitqueue head for events */
> -	wait_queue_head_t event_wqh;
> -	/* a refile sequence protected by fault_pending_wqh lock */
> -	seqcount_spinlock_t refile_seq;
> -	/* pseudo fd refcounting */
> -	refcount_t refcount;
> -	/* userfaultfd syscall flags */
> -	unsigned int flags;
> -	/* features requested from the userspace */
> -	unsigned int features;
> -	/* released */
> -	bool released;
> -	/* memory mappings are changing because of non-cooperative event */
> -	atomic_t mmap_changing;
> -	/* mm with one ore more vmas attached to this userfaultfd_ctx */
> -	struct mm_struct *mm;
> -};
> -
>  struct userfaultfd_fork_ctx {
>  	struct userfaultfd_ctx *orig;
>  	struct userfaultfd_ctx *new;
> diff --git a/include/linux/userfaultfd_k.h b/include/linux/userfaultfd_k.h
> index e4056547fbe6..691d928ee864 100644
> --- a/include/linux/userfaultfd_k.h
> +++ b/include/linux/userfaultfd_k.h
> @@ -36,6 +36,45 @@
>  #define UFFD_SHARED_FCNTL_FLAGS (O_CLOEXEC | O_NONBLOCK)
>  #define UFFD_FLAGS_SET (EFD_SHARED_FCNTL_FLAGS)
>  
> +/*
> + * Start with fault_pending_wqh and fault_wqh so they're more likely
> + * to be in the same cacheline.
> + *
> + * Locking order:
> + *	fd_wqh.lock
> + *		fault_pending_wqh.lock
> + *			fault_wqh.lock
> + *		event_wqh.lock
> + *
> + * To avoid deadlocks, IRQs must be disabled when taking any of the above locks,
> + * since fd_wqh.lock is taken by aio_poll() while it's holding a lock that's
> + * also taken in IRQ context.
> + */
> +struct userfaultfd_ctx {
> +	/* waitqueue head for the pending (i.e. not read) userfaults */
> +	wait_queue_head_t fault_pending_wqh;
> +	/* waitqueue head for the userfaults */
> +	wait_queue_head_t fault_wqh;
> +	/* waitqueue head for the pseudo fd to wakeup poll/read */
> +	wait_queue_head_t fd_wqh;
> +	/* waitqueue head for events */
> +	wait_queue_head_t event_wqh;
> +	/* a refile sequence protected by fault_pending_wqh lock */
> +	seqcount_spinlock_t refile_seq;
> +	/* pseudo fd refcounting */
> +	refcount_t refcount;
> +	/* userfaultfd syscall flags */
> +	unsigned int flags;
> +	/* features requested from the userspace */
> +	unsigned int features;
> +	/* released */
> +	bool released;
> +	/* memory mappings are changing because of non-cooperative event */
> +	atomic_t mmap_changing;
> +	/* mm with one ore more vmas attached to this userfaultfd_ctx */
> +	struct mm_struct *mm;
> +};
> +
>  extern vm_fault_t handle_userfault(struct vm_fault *vmf, unsigned long reason);
>  
>  /* A combined operation mode + behavior flags. */
> -- 
> 2.43.0.429.g432eaa2c6b-goog
> 

-- 
Sincerely yours,
Mike.

  reply	other threads:[~2024-01-30  7:13 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-29 19:35 [PATCH v2 0/3] per-vma locks in userfaultfd Lokesh Gidra
2024-01-29 19:35 ` [PATCH v2 1/3] userfaultfd: move userfaultfd_ctx struct to header file Lokesh Gidra
2024-01-30  7:12   ` Mike Rapoport [this message]
2024-01-29 19:35 ` [PATCH v2 2/3] userfaultfd: protect mmap_changing with rw_sem in userfaulfd_ctx Lokesh Gidra
2024-01-29 21:00   ` Liam R. Howlett
2024-01-29 22:35     ` Lokesh Gidra
2024-01-30  3:46       ` Liam R. Howlett
2024-01-30  8:55         ` Mike Rapoport
2024-01-30 17:28           ` Liam R. Howlett
2024-01-31  2:24             ` Lokesh Gidra
2024-02-04 10:27               ` Mike Rapoport
2024-02-05 20:53                 ` Lokesh Gidra
2024-02-07 15:27                   ` Mike Rapoport
2024-02-07 20:24                     ` Lokesh Gidra
2024-02-12  8:14                       ` Mike Rapoport
2024-01-30  7:21   ` Mike Rapoport
2024-01-29 19:35 ` [PATCH v2 3/3] userfaultfd: use per-vma locks in userfaultfd operations Lokesh Gidra
2024-01-29 20:36   ` Liam R. Howlett
2024-01-29 20:52     ` Suren Baghdasaryan
2024-01-29 21:18       ` Liam R. Howlett
2024-01-30  0:28       ` Lokesh Gidra
2024-01-30  2:58         ` Liam R. Howlett
2024-01-31  2:49           ` Lokesh Gidra
2024-01-31 21:41             ` Liam R. Howlett
2024-02-05 21:46               ` Suren Baghdasaryan
2024-02-05 21:54                 ` Lokesh Gidra
2024-02-05 22:00                   ` Liam R. Howlett
2024-02-05 22:24                     ` Lokesh Gidra
2024-02-06 14:35                       ` Liam R. Howlett
2024-02-06 16:26                         ` Lokesh Gidra
2024-02-06 17:07                           ` Liam R. Howlett
2024-01-31  3:03           ` Suren Baghdasaryan
2024-01-31 21:43             ` Liam R. Howlett
2024-01-29 20:39 ` [PATCH v2 0/3] per-vma locks in userfaultfd Liam R. Howlett
2024-01-29 21:58   ` Lokesh Gidra

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=ZbihbPMZO2gT7mB4@kernel.org \
    --to=rppt@kernel.org \
    --cc=aarcange@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=axelrasmussen@google.com \
    --cc=bgeffon@google.com \
    --cc=david@redhat.com \
    --cc=jannh@google.com \
    --cc=kaleshsingh@google.com \
    --cc=kernel-team@android.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lokeshgidra@google.com \
    --cc=ngeoffray@google.com \
    --cc=peterx@redhat.com \
    --cc=selinux@vger.kernel.org \
    --cc=surenb@google.com \
    --cc=timmurray@google.com \
    --cc=willy@infradead.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;
as well as URLs for NNTP newsgroup(s).