From patchwork Tue Feb 13 21:57:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lokesh Gidra X-Patchwork-Id: 13555745 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id B02B4C4829F for ; Tue, 13 Feb 2024 21:57:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 41F798D001A; Tue, 13 Feb 2024 16:57:58 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3A5AE6B0082; Tue, 13 Feb 2024 16:57:58 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1F98B8D001A; Tue, 13 Feb 2024 16:57:58 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 074B46B007B for ; Tue, 13 Feb 2024 16:57:58 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id D29EB120CFE for ; Tue, 13 Feb 2024 21:57:57 +0000 (UTC) X-FDA: 81788143794.14.15968F1 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf07.hostedemail.com (Postfix) with ESMTP id 1C43240017 for ; Tue, 13 Feb 2024 21:57:55 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=TonrWpv4; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf07.hostedemail.com: domain of 34-XLZQsKCBQ584yC102xBu08805y.w86527EH-664Fuw4.8B0@flex--lokeshgidra.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=34-XLZQsKCBQ584yC102xBu08805y.w86527EH-664Fuw4.8B0@flex--lokeshgidra.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707861476; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=FeTp34JzZtDcGzw26Xy4JuyVdUXeLDl6wgD9/498E4U=; b=CjBQD1yuN9Wmpgj6lwOzzGf+w/NknKPc6L8JyBbRG++g87Qq0HAhec4pxwcrNwk3qmENWs lsO9IgkuT6X4h+LhO8Oc46F77cHc9fTJ9WnEEyHMZpHCqkPsTmsJjXyzzolihkjj/2omN5 N4rQPXD57kU4klxPfDoxVAEqWJy+61U= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=TonrWpv4; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf07.hostedemail.com: domain of 34-XLZQsKCBQ584yC102xBu08805y.w86527EH-664Fuw4.8B0@flex--lokeshgidra.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=34-XLZQsKCBQ584yC102xBu08805y.w86527EH-664Fuw4.8B0@flex--lokeshgidra.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707861476; a=rsa-sha256; cv=none; b=Xja8zFNJt7VENBCTYuYLoqC/HAXPAT6034w1JEORN5NpYGDwm4gHfcK0oDmsqx1BEIorVK q95XnCofQwKigyUBfpzs3dJLeuE7UGl2MCNxt3FlueP/8KqwIrc5PQJAbrOqV8MGbrJq5p 7WZ1rSLZ5U1msGm8+GkKYKBULKBjZ20= Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-5efe82b835fso109011837b3.0 for ; Tue, 13 Feb 2024 13:57:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1707861475; x=1708466275; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=FeTp34JzZtDcGzw26Xy4JuyVdUXeLDl6wgD9/498E4U=; b=TonrWpv4lT1UHawVVB+k0e1kMi8LoxK63B5PwghvAMYG5/vqdhxa97CXMF2x5q6BYQ 0I2cHtAhCMo52SCfL3lcROP+jQMSkodgcvrxZfPIr+st7W+QnN9VmvAiW7gsL+DLhFPH 9G0WYfBknp2t/5ocbqPSVDOdXq9d5yNFWAYuLjfxMNIRsb+a3VHDjHx5Fhf4VJKG8No+ 2PKPLmWcT2p0/U31oEPgugv3pm1+9LX6EnwZnks8oQnP/Ne6I82dVknigyauQ0A4OsTA rC2XDhbPqELPnGNc0vPgqTohagzH1Ggd49BNR99K4sJELs2ayop+vD4eaey314+RQQxd 1fQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707861475; x=1708466275; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=FeTp34JzZtDcGzw26Xy4JuyVdUXeLDl6wgD9/498E4U=; b=qUTY1Q15IzxP/I4y2VvHDVpMPKgKA0LyDXZFj/ocNbUGE+HfMlm78bZ6p7Q2lzpOzi sn4YD4igxcvNCT0JN29Zm2N5IDqlFGJ9qkZNr7TomEZpYWM57UBxUITw47qQSkKcc8B+ /mujoyJUQ4IqqD8NxGCR33eyla68jt0hQrCT8hw2fHVnF/uHnTDVAGjGLeY94Y99/c3n 2q6OBuWYpapbxrKlmemWWVDHANtLHE2smMaS0cYsUMi5tELPurkePbN5t/YjyGpQsmYo xsuNc1uwFtgiT2/bICvEXwNg/KarEHSV47swPmV7a7L1uZF9AuGmGLyR298FqeP+KlML zSUA== X-Forwarded-Encrypted: i=1; AJvYcCUXCaPDBj8bnEMbFcJZ4RHTaIr4PXSmdsXIWNn4jd0s7bzjNe0M8oQSmFOsn6/Lf2Z2+HrqC/+2f4Svq1OljRITJ2E= X-Gm-Message-State: AOJu0Yw9P/At4K0xgHEU5FMJLxqVeRtP6gsbLUvqGxixayrNagbxE0EF VpegxXV7GkgZN030Nx/Ukdk0tTlKW+Gt+ejXTZ/xdHmfyCTc6yB2D/r1EsdctrB11QSDLwb9ABm 2sWgRHyyF08XacZcSDZkucQ== X-Google-Smtp-Source: AGHT+IF6FRAl67GGzZTs+uSDLQ3zEXnXXJGoppNG6Drbo0W+NjY2DiKJAS+tQbv/WS3Q7Q/R1NWID6lqQwyYNbHC0w== X-Received: from lg.mtv.corp.google.com ([2620:15c:211:202:ce6c:821f:a756:b4b8]) (user=lokeshgidra job=sendgmr) by 2002:a05:6902:1021:b0:dc6:fa35:b42 with SMTP id x1-20020a056902102100b00dc6fa350b42mr95095ybt.2.1707861475235; Tue, 13 Feb 2024 13:57:55 -0800 (PST) Date: Tue, 13 Feb 2024 13:57:39 -0800 In-Reply-To: <20240213215741.3816570-1-lokeshgidra@google.com> Mime-Version: 1.0 References: <20240213215741.3816570-1-lokeshgidra@google.com> X-Mailer: git-send-email 2.43.0.687.g38aa6559b0-goog Message-ID: <20240213215741.3816570-2-lokeshgidra@google.com> Subject: [PATCH v6 1/3] userfaultfd: move userfaultfd_ctx struct to header file From: Lokesh Gidra To: akpm@linux-foundation.org Cc: lokeshgidra@google.com, 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, rppt@kernel.org, Liam.Howlett@oracle.com X-Rspamd-Queue-Id: 1C43240017 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: aw1yca5woahoqfzmo7ot5hjnra69uxwa X-HE-Tag: 1707861475-215277 X-HE-Meta: U2FsdGVkX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pbPG3VyJhMBOzkaPFsub3GZkC22xKf2aCZGS4WgpL3QnrNCgQnjE3JTknEQaCjC1FDCfr9UxuuHRFXQFuwYLBJybv9+q0I90fqdxFSZtwvaKbfLOyN9NjNYI0vrS+eo5KVJzkRDpaKuc9GvmVVGoUuKEbapI9n2pT4bL4O9AL9/cjvxhmm2DkAhYCPgH0O1Jt/DpZ2wBv7ysnTOqnLtgt2Jozuot4SL7v8I8jV96aQmWHGzpZPUkasI6BpE+j6uokrWLkso+6HCXzvVVRwAReO9BtuxuNm6jrcN7TR3/Rwux2Qd7lsfz1zQZeoc+iN26kAJI0vkyyuku183zREvxdABsqT9y1NwRxfhQeb9h9n9YlXDTuu77TIuH1m15jDQUb2R2xoOAoGI4CXf2w4lNoWD7e/jFPDkaMKTTmB9r25M1wSK98e52Yhx7rySjp3yUn/3H48TLauBqrBX1F6SPqFz0dR2UP69J6v8UkbY54+72o3ESChuy0eHNJEOguW2J0p3WmngSQ6VpiN7TiCfpllzRBteyAP+ErxADYmjf5gILc2n9SjtvSO8yRV2NMV8DleY4zySP0MZM/JFcqFyqI20UTatLv1xqSgzDTOvco3gCkW6xaP+6AGUZ+Hy7Cv7SI9myAvTZPEaKfB70DsuS1IUGYTYISz3ZjoMi9SPK2bqTPcxNBwBuct7L3M/U5RxccNN6z6VsDqmzHHHJ2CRcVAfdVXXR1Uuuc= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Moving the struct to userfaultfd_k.h to be accessible from mm/userfaultfd.c. There are no other changes in the struct. This is required to prepare for using per-vma locks in userfaultfd operations. Signed-off-by: Lokesh Gidra Reviewed-by: Mike Rapoport (IBM) --- 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. */