From patchwork Thu Feb 8 21:22:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lokesh Gidra X-Patchwork-Id: 13550492 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 422A4C48260 for ; Thu, 8 Feb 2024 21:22:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AD8D06B0080; Thu, 8 Feb 2024 16:22:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A617F6B0081; Thu, 8 Feb 2024 16:22:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8DB126B0082; Thu, 8 Feb 2024 16:22:19 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 7D8866B0080 for ; Thu, 8 Feb 2024 16:22:19 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 60E3B40F83 for ; Thu, 8 Feb 2024 21:22:19 +0000 (UTC) X-FDA: 81769909998.20.5E42677 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) by imf14.hostedemail.com (Postfix) with ESMTP id 9686C100010 for ; Thu, 8 Feb 2024 21:22:16 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="w/2XQkuu"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf14.hostedemail.com: domain of 3B0bFZQsKCNwJMICQFEGBP8EMMEJC.AMKJGLSV-KKIT8AI.MPE@flex--lokeshgidra.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3B0bFZQsKCNwJMICQFEGBP8EMMEJC.AMKJGLSV-KKIT8AI.MPE@flex--lokeshgidra.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707427336; 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=nf0ZIGTIbLHsz9eDXuov4Krva17PffhTT1M5Z9/pa8/6MR3Rbetf233mnS9t3GpfmW973U 53ruxUEO5peKesBtO1FhkZ07XbUrrpAfiQFrUTEX9OFLAVIJaWzhcV1+Y3Yp8zFsY2HxJ+ QYTt3PCKueUht8YBnwe/iDzRU1A9cjA= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="w/2XQkuu"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf14.hostedemail.com: domain of 3B0bFZQsKCNwJMICQFEGBP8EMMEJC.AMKJGLSV-KKIT8AI.MPE@flex--lokeshgidra.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3B0bFZQsKCNwJMICQFEGBP8EMMEJC.AMKJGLSV-KKIT8AI.MPE@flex--lokeshgidra.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707427336; a=rsa-sha256; cv=none; b=3UZZTMKIwy4qWWdaYoOzVmjoFul9q7H7j1gG7rTqt4uBMOiJkBEQHMzjweeWbkdL5+IW8L pBl+CNFeTNQewCSnUzRJhXaGu1ilsC3397JtCVZKfLDHb+JwIYX8rJUpdC4xMI4C42utxp HaJxFIuy6QaXv4LH/bdnOpb1lPFyshw= Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-604b44e1dc9so6570777b3.1 for ; Thu, 08 Feb 2024 13:22:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1707427335; x=1708032135; 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=w/2XQkuuYtIlAC+aUhY3HF7SBprsrEJvgTptn0pPAICMRDyn4fjeNnjeIYuN+YdSEN qNA+CHefwXdsj2RJFKUBpOYi9E0DPPgfFQkn5V5egNKvLfdp1s2/DoE4Ea3Qo7iuAJPb aFVyENl92t0y/J6bSiy2o8MsrQuEBSjReS8bSW5tBmiNwgzHDHyV4T2kdqW5CEJALlhI VPmoMvO1qT/EGIhUPiQVb3X/IpokFbT04SYxSkliehTc45fpx3efgyXG1hYI6jiYAEo6 JoUqOMMW821EFk4pwpTLslZRK2MmaqdxWdumgIp4MZ9Wn9MvVIr/pArQeDIumr4axA6m Eaew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707427335; x=1708032135; 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=nrPqIedzVar5Jo9ewrRkkYZb17wVI9CNNGr/D+zoDzvrcQJTiOuIUibeknvYcApx+n 3KK2yTWozaJVM0Np+65w6J3U/NO5paSRD5+LUwiQ4dG70nssYXTzDWdXfCRe3nfkL8yc ySir8cvpIfA3tAo7j2rhXRlgwCft1DZViNhplQ135GkjKk8EfLrR00Dd946VRvQQGBNM CYZYC0+v6TyA0anNL9r0vc9tlXKJ9C2r8ivWCo04pdjY/0UOvx+JkQ8z0J/kHUoHL2E+ q3m4OzKDusZbNo8ZejuAkBWywLQQDdT+cdWbCCMf0xP1bR+tP2Q32kzEhoxBedWE6GZ/ a1xA== X-Gm-Message-State: AOJu0Ywfd2S56s8B/E9Pmze96tYpIHKfcSPhd9yPmo6sm+3SSQA/bgFe xtJNhZtW1GFRAf4VByWSij/0yrihvktRj3huQho52KWBLXBttKb3iBb89c7kfAOhI+uZ8kb1J0X TzfaHmfuRY+3u7Ql8aFNJ7g== X-Google-Smtp-Source: AGHT+IEU/rITDSgvPlrw4EgfUfRceJKqlUTpaOVq6aKKDnlTmsQYo2lPuV1sCIYnSwJGgLrvzLIw+YSJUuAsvhO0Tw== X-Received: from lg.mtv.corp.google.com ([2620:15c:211:202:e9ba:42a8:6aba:f5d5]) (user=lokeshgidra job=sendgmr) by 2002:a81:4e85:0:b0:602:d545:a3bb with SMTP id c127-20020a814e85000000b00602d545a3bbmr93801ywb.1.1707427335604; Thu, 08 Feb 2024 13:22:15 -0800 (PST) Date: Thu, 8 Feb 2024 13:22:02 -0800 In-Reply-To: <20240208212204.2043140-1-lokeshgidra@google.com> Mime-Version: 1.0 References: <20240208212204.2043140-1-lokeshgidra@google.com> X-Mailer: git-send-email 2.43.0.687.g38aa6559b0-goog Message-ID: <20240208212204.2043140-2-lokeshgidra@google.com> Subject: [PATCH v4 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: 9686C100010 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: tkrssf7th9zienxims77hossyi5eicgo X-HE-Tag: 1707427336-238809 X-HE-Meta: U2FsdGVkX19Gia1aRqqso16lEWVGoZIF1BzAask8eSvz6iKGgVYiCJoTHMBSBsMLl5oFmTa37/4/rze27hhZXPDGI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PXxg+uTa3oqvasiqVgtfHqhJg5rNX40Omb4DX1UbDhAz2WDjyppG4aZZ+NiA/BBxdO5zRP0rhU9nOr0s0hSKDL07VyjkPa7BCl2QF21nPh7iq/+Urmah+HSlIkkv7hCjdz6oW0ba9V85+HJuLiRYBNkTpEiXwfsnQTrggo3YaEh7xqg2oE9XRe2VVHxhehM5+AO+mVmAtfAkQOlyPjmPx6Gy8TkmG9xD8T+166Tw+TRvodjdpRK/1w7HBCjyEoh6EqV597W7UZjgrDT45ahMjJoSbk5CSt1nEecH0JgIoZsONq+pv7wFVQhuiWfSVcBDc6IhrWdhUiBCfA2239TZLdOj7tyceNzz4JRo5tN73unpcEmTC+DiFe7aZL9911+cSREOX/AgIQarTsBddl5AAAWgKQzHoT/PnN0nNBdCTE4Ai7P96BReoyPkyJyREzQY0thQm86K9CbWS+emGji80pgtmppHYhzXSsnc7zktPl09jiFvTeP7kHWsCOD96W3t1Gi69NMpRSkBkUv9LQ/o2PC95aQzQxKkivrKo5H6B+9Ss/O1oVnKqNhFix691PIjiJEIwVSqavuXdBR2JqI5+5v/qPMpc03wFi0IU2i7BC63fUgwCrwu8ScVPZbti9p9BO+odKsmeUFa+GNXFT4= 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. */