From patchwork Mon Jan 29 19:35:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lokesh Gidra X-Patchwork-Id: 13536308 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 E6351C47DB3 for ; Mon, 29 Jan 2024 19:35:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 782946B0088; Mon, 29 Jan 2024 14:35:28 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7328C6B0089; Mon, 29 Jan 2024 14:35:28 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5FB0B6B008A; Mon, 29 Jan 2024 14:35:28 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 4FDF36B0088 for ; Mon, 29 Jan 2024 14:35:28 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id E2A13160A45 for ; Mon, 29 Jan 2024 19:35:27 +0000 (UTC) X-FDA: 81733352694.26.8A159DB Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf22.hostedemail.com (Postfix) with ESMTP id 1F115C0017 for ; Mon, 29 Jan 2024 19:35:25 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=D74itNlL; spf=pass (imf22.hostedemail.com: domain of 3_f23ZQsKCA4z2ys6vuwr5ou22uzs.q20zw18B-00y9oqy.25u@flex--lokeshgidra.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3_f23ZQsKCA4z2ys6vuwr5ou22uzs.q20zw18B-00y9oqy.25u@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=1706556926; 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=RxV5wBXLAd7sIIElP90tsYG05NDDw/o/tErBcn9qBHI=; b=Gu+dxpRjhIgxAW3t80kPecxX8nQl/tOLlqu9Cs+niJCZb85DT1LxKmY0eupkieozeQx4nG /Q2oNj6tofiGxBgi77oo11UMLNFD5RguBDauaFr9K4Hq6CKDs4A4NvbAzSEQtOTvw8qSnr joMV7mVTWdJnfbGdSIE7r4EPOgrYR4I= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706556926; a=rsa-sha256; cv=none; b=A0gWunW05CW1jXpOIr7Px9LuV8FiZvaZ7YPiw8Bp5yuaxB+GfTcdhd8Rr/EX0jhc4NbjkO NZwT+ZxcMJlAZAH3/gNL7cDHy3W1DRKg2CyFs+3OmWGp1wcHA52/hPtaE3UfSLsDYoPc6L 96gVG1DpnBzjWx0+IIbKdlosNzvKfHU= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=D74itNlL; spf=pass (imf22.hostedemail.com: domain of 3_f23ZQsKCA4z2ys6vuwr5ou22uzs.q20zw18B-00y9oqy.25u@flex--lokeshgidra.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3_f23ZQsKCA4z2ys6vuwr5ou22uzs.q20zw18B-00y9oqy.25u@flex--lokeshgidra.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-d9a541b720aso5607091276.0 for ; Mon, 29 Jan 2024 11:35:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706556925; x=1707161725; 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=RxV5wBXLAd7sIIElP90tsYG05NDDw/o/tErBcn9qBHI=; b=D74itNlLD4glyusGFUSXLJzjCKuJJJpWeJ+dos5ITVvhXZWnoim0qnx0yhawYQ4pUA kz56vzCncrBsk+yTIYijfius1oz8mA/P4noDGU489xCvIxZOjNiACTaSvw+kfIHyMqyO V2XIjvCp4910wu/5I4/QEzhWam8WNxXtIeK5Bgf44GlGPbHcgCPV9mPDtCfLcDaQBPh+ hyq+IzQPEV+spnv+SC1gZbAuETJB31RZkl07Ye9yTJXuwVpzTBDww98YC0qOAuGWOp7q G1/X6PhU5gnmvv7iix0iK89/z+0khCJ/yQO2Ub4o1CxbgZDetUDuOmmqGCLYFOIC9nt/ 2gVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706556925; x=1707161725; 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=RxV5wBXLAd7sIIElP90tsYG05NDDw/o/tErBcn9qBHI=; b=FhlZmhQwh5GHrLA964Q0KY4J/n4wWzzGfbz5P5PA2spVsmyGYaQLI8EbmM+GcOBqbl 7r3fgZNU2dpzh3D7gBO/+s9/R/hfoQeAT8NRm7hv58CFHCXcIJf9kxDhir6i8/XEnbqt gFD+hqRjEkOd4Vg9DnBr1jfomau+rPW0p7IPz0MnL7f6N9I3lDSN3/PjqhkeMksybh98 oFiYxp+0o6suTVZIPpFxXveXju+qfCzMmLpzIn7ixrxiLlgdaCe5AYtjcAwpaLCqYMCi woszUR51joSrlq3UhreYg4RIpyYhjl0Kh1ivcjLFG3uLjCxiQlcqolSCvmuMAclBYyxF lOLQ== X-Gm-Message-State: AOJu0Yydso5Rh74ERtT6qZBUEprUMPf/aul+gHnMSRduvCjisLw9yJZK 4/25SuqFIOKaqkULosBSZMcdJIwlMZa3x09BcUYdrt9y7z8uC4UMWQyegCnlhjvF74LK5LT2c4V Lss+uglpCrifPQjkCRP/8Ig== X-Google-Smtp-Source: AGHT+IF32DkXw2QhhBn3l4mRA2HIAIDhN6YElkLAMaf3KndoLGpHhaAw9uQKXHl2RVkOyBG8Y0880v//3lgc+vKdmg== X-Received: from lg.mtv.corp.google.com ([2620:15c:211:202:9b1d:f1ee:f750:93f1]) (user=lokeshgidra job=sendgmr) by 2002:a05:6902:2611:b0:dc2:4ab7:3d89 with SMTP id dw17-20020a056902261100b00dc24ab73d89mr2460415ybb.1.1706556925300; Mon, 29 Jan 2024 11:35:25 -0800 (PST) Date: Mon, 29 Jan 2024 11:35:10 -0800 In-Reply-To: <20240129193512.123145-1-lokeshgidra@google.com> Mime-Version: 1.0 References: <20240129193512.123145-1-lokeshgidra@google.com> X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog Message-ID: <20240129193512.123145-2-lokeshgidra@google.com> Subject: [PATCH v2 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 X-Rspamd-Queue-Id: 1F115C0017 X-Rspam-User: X-Stat-Signature: w6aziyemmcgg56hg5xapw9o1angync1u X-Rspamd-Server: rspam03 X-HE-Tag: 1706556925-395698 X-HE-Meta: U2FsdGVkX18dooWA3xBMkgSQmSr3adfPKY3Aq0/gyqIbXlGUhjBAzUyFn44ioIz1bRidA+GsIkRNn+Ha+GYqYmxl3qtItKwhs6q9nYgKmdeLF10tuYbX80XK6c7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ECjGgwrxTCRNnmx0+S4bzGCRIXbYT+aesOjQRN1CkcDxPHc1v2czVlETSxcmhpf62qyottaKMxgHyaleXycHfJ0v4EL2yVu8ubWyxN3LiPA5pHpaHbFsVWxZrOmJVSX63FPOemjQut/WtKnoc+vHlRTOTnJkupJJElX6LyvjijEUSmVZTcZWi7T1qsjcj2AMorsciihbqfgk2eNcznppPqupajwurrSeY++TOtbhIFHNH1LJvKt4W6b64hr4Txm3u5A3UnzDdrtfx1VT4XSnoud8yLp1uK6Rl3kSx0QLgDVT5ctvvhanbkgFyKmXKiI53Rom/luQZ9VarX2yKrITBM5S55sRg1XW9dVrUejOM7+8L68T7ShDwfPQQ0VrSc1V34MqpEAA9x11r/nPRXWqP/qdrWbFpouicayULDMMu8r3ITCzKblVYJSHQzW5WKIfgBNR6Yt8j7p3JILiDvrlSHBY+T7tx8 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. */