From patchwork Tue Feb 13 00:19:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lokesh Gidra X-Patchwork-Id: 13554195 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 5FD38C4829F for ; Tue, 13 Feb 2024 00:19:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EA7D46B007E; Mon, 12 Feb 2024 19:19:47 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E574E6B0080; Mon, 12 Feb 2024 19:19:47 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CF89D6B0081; Mon, 12 Feb 2024 19:19:47 -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 C253A6B007E for ; Mon, 12 Feb 2024 19:19:47 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 895A51C1452 for ; Tue, 13 Feb 2024 00:19:47 +0000 (UTC) X-FDA: 81784872414.23.34F4C9A Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf10.hostedemail.com (Postfix) with ESMTP id F252EC0009 for ; Tue, 13 Feb 2024 00:19:45 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=AiC3e798; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf10.hostedemail.com: domain of 3obXKZQsKCGwVYUOcRQSNbKQYYQVO.MYWVSXeh-WWUfKMU.YbQ@flex--lokeshgidra.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3obXKZQsKCGwVYUOcRQSNbKQYYQVO.MYWVSXeh-WWUfKMU.YbQ@flex--lokeshgidra.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707783586; 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=ozUmCL0mQLu3kOwhLkKfGjhXoZDR0qC0AyLb7fRrCWM9KyjdgJ5rollfD4JeXblnrRN4wY sKFYW0bJYHA6h3v4FtfGugdI7KNUt/Nq908ToWh/EAg5Pv9xyxWClKEuIifos0Tdy7XrNb C88IONr/wJwiBgh/mKSWZxbCouNVYLk= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=AiC3e798; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf10.hostedemail.com: domain of 3obXKZQsKCGwVYUOcRQSNbKQYYQVO.MYWVSXeh-WWUfKMU.YbQ@flex--lokeshgidra.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3obXKZQsKCGwVYUOcRQSNbKQYYQVO.MYWVSXeh-WWUfKMU.YbQ@flex--lokeshgidra.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707783586; a=rsa-sha256; cv=none; b=3hKbBjjFty/sFu9J81UgOaMySa932ExrBCr0zbFV3UBw3soPFOAAYBTnEjPfCU+c740IEb mUUirWuotFnizKPVuneAOi/+xSoidhB+rBsruDFBa3Mubfxh4BHWQToClG7cHu7XW6oDGY 7k8sTnCFnGv9s+WZyulZsNnH3PX4tSo= Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dc6dbdcfd39so7811062276.2 for ; Mon, 12 Feb 2024 16:19:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1707783585; x=1708388385; 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=AiC3e798lGMa4H2JKaWshzK8klH8+/eEUFRuE9RCtXE0jrn/0RtASJ3SLqaJd2krNq euda5DTdR+Jq7GTp+MQ7B9EK+krsGly89LsXvs9OemWnNMgEIfmZnNRwPxr8VLz/HmLr JeF6jtbFvo7G18h0gXlgdku/3lBRnHoNA+IO7eu2ZJZD4F8eLQFtHqLTo8S61if08LAQ PIVIpW7Dr0xcwFk+cyVQEv1TwGW0F1Fv8BKtisbsAFq6EwQQx5FDZag9ZdF2p7hcQCPQ SUw+Vnxg+hPNkKyL13Sb0jHHxlIbOffoTMf1RWZpXcRcjU/7iFRRHTxKNcIRAQ1OcMQe ruEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707783585; x=1708388385; 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=EnQUnKDQN1x9Wsb0CRygpIMsES2BvjJELpV3RIcFdXchRBLKkw9ASngH8DxB9qAy/T yslO8rRbeJNsRWqLRVr9CWoxn/2x6HvriGSqy+apxcT/RCx0JMoMPUO9QEYQHoHe7X8l enI9AuaGixXwYkbe3enudp11yER74YhIA0hAyEao2e5GA3x7yiYET8IVO6Kizswaj9Pb Ko6HquO7vViQzjRnaFehl0RIQKNdUruPZ61iTuR5MstmyXmmQfUNbcH6MBhtFGcLW5Mn ica5rw5GutjGYqZnY00AjXFYp1YmNZSy0D9tu+tqmWrWdMxJ7TZyBkR6LuZYUgIl62YT xZ6A== X-Gm-Message-State: AOJu0Yx/aVVQw8ZAcJv5xBAM9c9tkf8It9GYDrVqPYC2MEgQdrVULcpz osLsyZftyTuvm+Wb0HwA0QPItyDThWDCT7Mhz0CADjqITN3gBjilDsXG77T3kOzUIJvXesogrSL 3FIuV9O65fe05dUcdzqQiNQ== X-Google-Smtp-Source: AGHT+IHHF8psOCpR3jPtRIweQhip+WhYFn+NGs+b1/7N2Bm+HUMlIaS9Pt1A9QzZr7uT4pBB5l5vrCPMXQlp/u7k7Q== X-Received: from lg.mtv.corp.google.com ([2620:15c:211:202:fd80:ef0f:6359:fc4c]) (user=lokeshgidra job=sendgmr) by 2002:a05:6902:10c2:b0:dc6:d2c8:6e50 with SMTP id w2-20020a05690210c200b00dc6d2c86e50mr1289834ybu.7.1707783585214; Mon, 12 Feb 2024 16:19:45 -0800 (PST) Date: Mon, 12 Feb 2024 16:19:18 -0800 In-Reply-To: <20240213001920.3551772-1-lokeshgidra@google.com> Mime-Version: 1.0 References: <20240213001920.3551772-1-lokeshgidra@google.com> X-Mailer: git-send-email 2.43.0.687.g38aa6559b0-goog Message-ID: <20240213001920.3551772-2-lokeshgidra@google.com> Subject: [PATCH v5 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: F252EC0009 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: bn1hxxurcbzcunr6fsu9swad5xe4y9hp X-HE-Tag: 1707783585-98617 X-HE-Meta: U2FsdGVkX1/2yDNFVLnK0OFPljKCK0O0i6RGuHIkFv4rYFb+C3ZPu5tKpgXvFcNJogD0tl4I8ve8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RSV5QptHylHM8U/vVXYfSnQnKEF2yP01KLtv01PNsWxKMe99Km/Z+RYtVaCZ0Oz3cYfJm6s5DvlBM/vqJX26QCwZAKjBiR2BzR1z8YcGhVmwy0JKOVYpd65Ni19NIjb9k/iWw0fTEavRkAh/x6ZLOXrpqTdmQQSdgwuSHjHXGGuHcdqVhQs38qUxT73SsARHXzIqTfBBVZMN/l3izhOahppvjxUSoovUS+rHT0PbYSrXGPLvTnt9CDk6U5m4pGdQEp/0FLxKQ8f55GNug1j6C8jcEJzRQCm0xxcWFFDfAMzNYZuvlfmZMAAzj1A2yaYiDXr2DHO9bJ 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. */