From patchwork Tue Feb 6 01:09:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lokesh Gidra X-Patchwork-Id: 13546497 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 9F879C4828D for ; Tue, 6 Feb 2024 01:09:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 203826B0075; Mon, 5 Feb 2024 20:09:50 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1B3C06B0078; Mon, 5 Feb 2024 20:09:50 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 07BAA6B007B; Mon, 5 Feb 2024 20:09:50 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id E9AFF6B0075 for ; Mon, 5 Feb 2024 20:09:49 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 8975040B53 for ; Tue, 6 Feb 2024 01:09:49 +0000 (UTC) X-FDA: 81759596898.16.78D6F25 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf12.hostedemail.com (Postfix) with ESMTP id B972F40002 for ; Tue, 6 Feb 2024 01:09:47 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="jejsq/lM"; spf=pass (imf12.hostedemail.com: domain of 32obBZQsKCCMKNJDRGFHCQ9FNNFKD.BNLKHMTW-LLJU9BJ.NQF@flex--lokeshgidra.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=32obBZQsKCCMKNJDRGFHCQ9FNNFKD.BNLKHMTW-LLJU9BJ.NQF@flex--lokeshgidra.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707181787; 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=l0Wsa/otXfcNbNeX5OxfMRaNnAPGn+xliclZzLODRNs=; b=V5LZLHzegUl9ymx4JrzzmoGdliZ0hSRPHx2lxdV9LpqWTEYMmSHtLzVT3g6zN9WimCVSF7 HcocX5wqW2kQ3lK0zVV2olYGGItm8aSQ3UHmrttn8KpoVh4D/z/ng+2U5ZVKeYc8k8yKm8 AJmcl2sBGAeCmEh1sm0ZRWlpGDX8uD0= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="jejsq/lM"; spf=pass (imf12.hostedemail.com: domain of 32obBZQsKCCMKNJDRGFHCQ9FNNFKD.BNLKHMTW-LLJU9BJ.NQF@flex--lokeshgidra.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=32obBZQsKCCMKNJDRGFHCQ9FNNFKD.BNLKHMTW-LLJU9BJ.NQF@flex--lokeshgidra.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707181787; a=rsa-sha256; cv=none; b=UxnXtZ2YApsoTf2Iqlgu8ab1Pp0CYGi50S8I1/ZavXg2eu+dBqH1ayuDKWUzioGxPoa/wM umbLs/wC9yf/q0iP6+6nP6KGJniXzI+YDi54gS3QQk9C4mkor3zJYfPucj1rutNHjsCjTf 50FpX46k9GpHRD24hHflkw8OKbu4lEw= Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dc693399655so8096927276.1 for ; Mon, 05 Feb 2024 17:09:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1707181787; x=1707786587; 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=l0Wsa/otXfcNbNeX5OxfMRaNnAPGn+xliclZzLODRNs=; b=jejsq/lMSV2hpSaDz0gb4B0eeoxUaYPR7Qmp/RKRL675IiFdAmZqAaQ44HLPLLPRCk +yOEKmKXzLc99clPRfRpLXR6DHg/5FxT29Jy58Ba6rRxOAt4H+VJM7G/XlSkF9A+g2ov k7vKFazSqA2ivGvEMfiM63kCzGWCe19lwGZnxfzBc127AHARAVxlygsVBgN0uKV2ju9s Gxm0nSoSKcbtz2W8hH7tQWpSpo9zSqt9iY6P+vX7NSTWojNOLWqkRSmT5XRnX4hv95AN 0SIjARDTvQZlcQl4sv7bZxPgcA/0UtOlMCIjeYIhCWADdu/mpuhTqOYPa2xV5EWx1qdu Ugag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707181787; x=1707786587; 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=l0Wsa/otXfcNbNeX5OxfMRaNnAPGn+xliclZzLODRNs=; b=jUpaKO/xWX3c6BfppKZgde5xJTL8au3ClMXVp3bhGBN4G5oOdTga8i/rhawhLsxWyG yon8SZXTN3niJKApLSkaWiW8uiqcQCaBg5ZJqm2PFQmnP9C5NjvWLNeBmEKu8UOoJlv3 S2nbIfTedOik2ASJJlYpvr+dv39BMvgn2G7PinnPGu3ohPHjrFZOU+nLLf3Pdaa/+lVO fNTq1lZxAMptCM2p61uXQ+HsFT+7i8dPjhXAbTjLKp/1uVGAn+QQ0YPbruz6tjZnHH/u SO2KqJXqfDdJn7KB87PyYWcom4W6Fi8aSGJVcWtK4ovjE81jnL2yaw8/PQciLSGRz/J8 /2jw== X-Gm-Message-State: AOJu0Yxxo3nJ60IiyugykK/L1pD6CJF6MXqvhAYVIPKHkX5QjFolzFiQ 0LtjMUJm83+/KPnlO6mEaaQFcPhqMg7O0IBOMu6vDE+nb6PqSgVlGLjXMXp66+Ti7ZMPOWyHZIO FzZRHMm7G8INFsLLsrg1BIg== X-Google-Smtp-Source: AGHT+IENlNSDcojoxWkSl049zlYz4bm/u4F+E9+JQ3HrIX9YrhW8LmpdpxXCyJfTB1mNb9KyDkiJPwezJtg2W5ykyQ== X-Received: from lg.mtv.corp.google.com ([2620:15c:211:202:713:bb2c:e0e8:becb]) (user=lokeshgidra job=sendgmr) by 2002:a05:6902:13ce:b0:dc6:e90a:7f2a with SMTP id y14-20020a05690213ce00b00dc6e90a7f2amr53474ybu.5.1707181786937; Mon, 05 Feb 2024 17:09:46 -0800 (PST) Date: Mon, 5 Feb 2024 17:09:17 -0800 In-Reply-To: <20240206010919.1109005-1-lokeshgidra@google.com> Mime-Version: 1.0 References: <20240206010919.1109005-1-lokeshgidra@google.com> X-Mailer: git-send-email 2.43.0.594.gd9cf4e227d-goog Message-ID: <20240206010919.1109005-2-lokeshgidra@google.com> Subject: [PATCH v3 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: B972F40002 X-Rspam-User: X-Stat-Signature: bggd3qh8w69rdcn5cpyt48pwrbeykubc X-Rspamd-Server: rspam01 X-HE-Tag: 1707181787-668344 X-HE-Meta: U2FsdGVkX1+fV+hfSuR+ZA4F61GwSJhIRWU/qFBcUoDJjVkOUh9GA/B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wTaFSeCKSJwOAIwG3nHiJBM4TLyHw0aXD+gb9F8UxUL7vlv7UD084ZmjHCuCXSE0kZIrCuTvFN5kL8L2uDQoNB8NZ5lVR9wKEd5hvs3NfV5ywMEnvPOsPyD+h0RX0kjsMyMUT1Tnhsd1uzd7bP2tCJpKpbB0ozIAzt+x/8r8P3s1Ybwf7qWbX7aN8t4RzioG+ITDu3iN7xOzgW65mV/58RsqxLiZxewq3vt1gGGSU8NOrKlT8sAtEyHjZLEb6AkoW+HzQdJ8wKUZCPjHlW1RR7Mb5pyvBAsygoDKAcX+qYaDus81RIKBTm1kla/A2btGuVIFVmg5Zwc/HBG/MZJWCmO2eaTTIxhAQYSawSOZoKXgMs2AAtZkKxU+Wt8eDFDUwJh2TRSmbRJLOIacGF15wYh4R8ftylTk+1rM4rjAxLiFpBQDorkQoCUjHU1Q2cDvLQJatTk/wUVAScdTJ9qsPf6g29KGHzV/PHY2GBgI1pagCMmJEwJANLpqONQetUO5qoxsaqWMTj+jh6nIuLytxZgQkonaZturoF7Md06qmosJxhw0CGeK41Ldby9T0E51orrFAsbtidMZH1lfEUfs4wPszsOIMOAZUh69cnGPHxCML5aATKvSeh6j 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. */