From patchwork Thu Feb 15 18:27:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lokesh Gidra X-Patchwork-Id: 13559022 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 AA1EDC4829E for ; Thu, 15 Feb 2024 18:28:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2C85A8D0007; Thu, 15 Feb 2024 13:28:13 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 24D338D0006; Thu, 15 Feb 2024 13:28:13 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 09F808D0007; Thu, 15 Feb 2024 13:28:13 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id E6A588D0006 for ; Thu, 15 Feb 2024 13:28:12 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id BB4F614124D for ; Thu, 15 Feb 2024 18:28:12 +0000 (UTC) X-FDA: 81794872824.17.61051F3 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf23.hostedemail.com (Postfix) with ESMTP id EB769140026 for ; Thu, 15 Feb 2024 18:28:10 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=zH84DqE0; spf=pass (imf23.hostedemail.com: domain of 3ulfOZQsKCNcEHD7LA9B6K39HH9E7.5HFEBGNQ-FFDO35D.HK9@flex--lokeshgidra.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3ulfOZQsKCNcEHD7LA9B6K39HH9E7.5HFEBGNQ-FFDO35D.HK9@flex--lokeshgidra.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708021691; a=rsa-sha256; cv=none; b=rRjbgmslFQwNOMLpVbxfHHMLZpqAHazWo4x+tqd4L8T3B48d+Q8FBW+Odh1SYkc7n+4VBf dooGfS2vMsNGvPO24EwEqGDuNk+JxM+5esGd/2XMKpKuLgUa/+9L9qLcRfU+d2azSK/TVx Sg3Rn1mwQopsWmVGbSaatdqGMhMt1bE= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=zH84DqE0; spf=pass (imf23.hostedemail.com: domain of 3ulfOZQsKCNcEHD7LA9B6K39HH9E7.5HFEBGNQ-FFDO35D.HK9@flex--lokeshgidra.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3ulfOZQsKCNcEHD7LA9B6K39HH9E7.5HFEBGNQ-FFDO35D.HK9@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=1708021691; 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=5jFzOipv9bDJZnpb7UwZ8Eham/ShclgiDNDH7Ow4z+0=; b=ZhiaFicWHRmRwLEZLsD82b4xNfQSAM9MV/jDOdphOHiZsvfYOgFY1IhWSNFOkGblntecD7 YjhtZyX1QH28fp8qeinTLTv3vSNCFbAoL/+A9sng00ZNRJp1JdnhNBp4UBbkEW8NydUT+N 28Ll3ELDJCJz+cq07BqvZoxpMPxpoCM= Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dbf618042daso1854489276.0 for ; Thu, 15 Feb 2024 10:28:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1708021690; x=1708626490; 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=5jFzOipv9bDJZnpb7UwZ8Eham/ShclgiDNDH7Ow4z+0=; b=zH84DqE0Dhbbj/Lo/RBJ0djVsc5hCv4TQcdlfQvGXhd8Q4Etwu+B4I6EVTFW+M2LWn hemfeVtizMkxmsUi5UQHJPJ1Jm8bf2gbT4lZRi2zNSaoXXZoMWd7Nk3Q1t2IyXmr8bm8 kE1ARz01X1VRHXKQS0k5FR2ReVQw/bDwh4ZsfUNCtlUYwLxH10EUaQnyYnWPEDu8kB1n LX+zgCWeqe6NGxB/623C0Y9M2z3qR9k+Q9r5jqZCVnt4EC8E+/2g1VhwTRTX8BXx91tX 8P+syaiNVBK0Aiyc3B573FG8ohLODWoJrj8NZCd/Ds7AmnVhF2PL4P07pfm7KQDIToaO jyCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708021690; x=1708626490; 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=5jFzOipv9bDJZnpb7UwZ8Eham/ShclgiDNDH7Ow4z+0=; b=C4bc4RrEegrooPbnh3tioEo+iChDaMS1u5DQrVN/9eOcdIXQSawEI6/0JSCZuYUjVu uw0ZRSooQUX4PXFDn2/s0IAxlAYhLp8v/s9xspl+ZF6kB+UfysIsS9iOierHig2PWzGq vv8FFvjUT5bp8t8ZV/AJIHpthzK2glvLOBJRa9yxAcGle/1C20a0Rl0XTIxPHBujNV2D Rk+OFhTyJyJHuOruIL4ptojxAqIiy05TuVvDHBIdGQq2qkuDt7Fvkwtniy06P0hfghgI 47vxlXnKZE4HVXZN/2gKyYD7GfVNWOSb6U0LWaHIqzAkqTb+WYllZGFqI7FaiwVLHGUJ O2hw== X-Forwarded-Encrypted: i=1; AJvYcCXwz9FyKtPJTeP+44SWY7d1XD8yG4XEhW4Gt5fN1GQDqizyOVoPzqZxFidRX1GuC1eW4MpefDsz5m+HT/hEDJvU9Fg= X-Gm-Message-State: AOJu0YxYsLybjHerKefQjwDxQ6hlNOXvONiHcZbBhSXcMfFZo0Ysk7fo IrtdgCNUu7+MiM+PyP9ZJ+iF8AJmzkXFwnqRF1ZL5eiGpcuLs7DOVL/YunN+4F+vBy5ICdTUh9H dvpfqyTMJy0jwgZeLAM/xKg== X-Google-Smtp-Source: AGHT+IHHi2mCkEldISrNhtoRZCLnocCFS9qBcw8e+39nrcye3IQvcjCcfdDQNRvMWp/R1wX/qkVergX2FymdVGvJXg== X-Received: from lg.mtv.corp.google.com ([2620:15c:211:202:6186:87a3:6b94:9b81]) (user=lokeshgidra job=sendgmr) by 2002:a05:6902:f11:b0:dc6:db9b:7a6d with SMTP id et17-20020a0569020f1100b00dc6db9b7a6dmr83663ybb.13.1708021690138; Thu, 15 Feb 2024 10:28:10 -0800 (PST) Date: Thu, 15 Feb 2024 10:27:53 -0800 In-Reply-To: <20240215182756.3448972-1-lokeshgidra@google.com> Mime-Version: 1.0 References: <20240215182756.3448972-1-lokeshgidra@google.com> X-Mailer: git-send-email 2.43.0.687.g38aa6559b0-goog Message-ID: <20240215182756.3448972-2-lokeshgidra@google.com> Subject: [PATCH v7 1/4] 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, ryan.roberts@arm.com X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: EB769140026 X-Stat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GFfK+NH WBR3gfvboGhRlZPAACcwLlr03OcyMOmwr6TJF4xCskEGscBCBTmd+Y+fKMx8HdTVrKH8ldCxqPrl0bHWcJ+w83i94QRpypU9jgKeZhXFDv+AO3IpndM4GktfSxQmbaniZMIvA22yqUlNbWdDBb3Li7oCTLRzrUQaXZwBlNv5sM3jE7sXxxXMn3IH7SfkCQgQChNZuecV5HJZ59R9r9SNNcCgRGXFLGtUfyG/j+hxlf7DNGX5iJlvUwVMIIg6bNwJiToe0bPhuDASfS1r2N2OON9dgWrVBfgCEQ4kBmFmdDW+kW5/5S1MDOjFQe95lO/XT7q1nievrcbQgiMrM4eHABQT1SXDAiX1iavZ3R9PJJ9vlMDlbRGu21dz325C+kIiKwkTVvHZzpfA6HpKkVQzgx1AT2DKZTnh846yWJ4orHbU7KuKJeLlaLFF67Afpn8Lg6W8prpTZpdMXI4upFz7M5T3srbRcSn+UicjHN7Fsz2mKSF8nff0p+wn+NVnukFLMOo1ukDtAsDtLAUrkAwEDgNUtzBF17Q6oODIynC26zSfIfW5M1eYY428IKD0unNlrXL9oKEY+fqQ+j4lvrJEFiyq30gGDILMR0X5ORlAXz3FgcZLkRhs4sLSS4HPrko+AoyKLm58G2/fJvGXKl0kHoMFTjhjIHl66lOfXHfkOx5yvWizFGooeVKYJAhxo0PHTaiI8LV1BRNHjg7C5+wWLjYSyGsHaD7bmWxxZzwzpGlvcEr20XshSUohucKdkf5NTI6hz7Yjz91qTvvQ= 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) Reviewed-by: Liam R. Howlett --- 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. */