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: 197130 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1249953dyb; Mon, 5 Feb 2024 17:10:15 -0800 (PST) X-Google-Smtp-Source: AGHT+IE/0OVa+DO6slpDiH/djdVJ14/6mtUcoUZROa/gJLd6qbqjBxCDpXAsfJ05JpEE5lmetWVT X-Received: by 2002:a17:902:c408:b0:1d9:83c0:a163 with SMTP id k8-20020a170902c40800b001d983c0a163mr194720plk.7.1707181815516; Mon, 05 Feb 2024 17:10:15 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707181815; cv=pass; d=google.com; s=arc-20160816; b=UTmPp5ce9YAnUOIE+Ws4onML0S2HbmzeGI8sb9nx9blPP4LOvAiLeep6BnC9Kk1DQR mfuUWAudONRCVCNUOZqPeMWrAunVAlLj07pBUGFxM1bl5T072Zlq4w6y22MQDpV7Lt3y KMAEJyouiYHldX6lgfVTuzQd6kjwu4DupMGoIQcra4vByWtWBArio53kcCSZBTOxKx+p rcJhvvBuaIZD0yLfc6NXxmhliQIxxfiET4NcZpBTHV4niTW70WPWP9tb+Mj649Yjvodu Rkq5JF0lJS3bKUtnCcjTnQVzKFCTpYnu2OICMTIeoV2d4vgVFEgy/jNbiQ/qjenrQ73B eiMQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=l0Wsa/otXfcNbNeX5OxfMRaNnAPGn+xliclZzLODRNs=; fh=9zLC1fqjCJpqTmuWp+VsvjgCAACmjQdL/+CM9ia9xGw=; b=B0bxrjC8tLI/tcIyhTsmczP3PMm1eqJisUz5DobKiA8+mJK3aiPotm0N5Wvug3kzCs uHxJajQlwXlv5ft6jF/g44bAVzlYUGzZx8aMdUj9tGjm7BcmcJ5TnEkYPG7C0H3Vlb8+ vQJzVqDRe63CFT9k74yFcE5ZTT0Sdsh75b8Wnxc5sluJH2vro5Xw5zFBvQl9z/DyGolR wrI3tRgzSSrIw5Yl6Hu7RNPd0YAD6Jzlg+TocBqCXafX7+ZawjXpRm7+46Zf7ONo5KV3 85tHpVZFElZQB2HCmfrkg/fUko0qrhfjTGEPnZg0P2c2lDAJCDMnK/RyqpYd1SvATcAG OWYA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=IkJeKvR6; arc=pass (i=1 spf=pass spfdomain=flex--lokeshgidra.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-54140-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54140-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=1; AJvYcCXzylTsLyvYPTA1puw8RfbIOUWr2vKeJJ4P8GUYdnvgscU6cqKatvIdaNwDwbkcpwDRORZy9inelDcTax1JjZNvWafmbw== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id s1-20020a170902c64100b001d9af7357a0si670142pls.622.2024.02.05.17.10.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 17:10:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54140-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=IkJeKvR6; arc=pass (i=1 spf=pass spfdomain=flex--lokeshgidra.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-54140-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54140-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 45A0B288003 for ; Tue, 6 Feb 2024 01:10:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A7279523A; Tue, 6 Feb 2024 01:09:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="IkJeKvR6" Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DC47D4A03 for ; Tue, 6 Feb 2024 01:09:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707181789; cv=none; b=a7k1LNUw3faiqRGSGdw8mA7YbBOxf3ngPqmc2GBXxrj63hZNkvHyVlGqnxz89fqdMboQa6dAjlvnyh8ACEOv9jQScFqr1caq4lay1T8sWaLtteAnZEzbNKFSeju4BYE22QgbXtcmiHKEVDmlkk/zyMkpZ7Q3f+mkBTed/WFhN5k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707181789; c=relaxed/simple; bh=bW5FqUi/xixapZsn2hg3bnkQMMB9OGn3jW6cVE5NBpw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=P3/MDbtah/n/WAhXoZMV4VsIR6wdcGwXHcvXq64tsYqq3wWjVdtlGNBR4WYJSWcsjUo6uWY5ZWW/wOzsh1nhUgJMdSTxVXf8SDmiG+dnS6kRMWGwnMP05tkXv27yaCvuRm/lcQf23fD3grOh6jiMhPDRgfy9qgg+mXwNzxnaqPY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--lokeshgidra.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=IkJeKvR6; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--lokeshgidra.bounces.google.com Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dc6c2643a07so9298524276.3 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=vger.kernel.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=IkJeKvR6Iclv0F+scZfsBuvRqyDqE7LSd1FwFesYxaZLtceS+MwKQTBgbVler14khK xvdjNJ7wWY0wa8umpb2erSiE4BB3hH+VPMuqbP1pW/0GPTRUWCp27R0iFio4HlZT+x98 YIQetP6lbogEreqEZSGdSulXWUiK7xU6F38xQGn87dds+edeeRisB2QK8XSUBmp8isDD Wf5bZytpzM4e80MQnk55AQRRRwApV2ZtsTpOKxjfhJwruatI6//zN4v0tkVGaDzfD8wG DI2ZvYXKbDENTQa0bN2fQ+BY1dcNMECQd85AYTikexsFS0vJvhblABu+aPAuqu4UpGWs M0Wg== 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=pD4Kqc358tkmqEmwp0WLp6epM8sEHMSTLB98sS2niZzHmdMCN37St0dF58p175goNn LhPMmqssvCD4+dQ2gK90AX+Ld2OxXXJPz0L2fwEwqL1ogK4PmNZz/3D/tEMiUBbw4d67 unL+9BAUxFlJDyGieWogrw7yUUIi16Sy6HsOSVT61bmNnpkCkmRjvPOjqzQqkT7ue8+B BwT9R5b0EzRv277CrDM/zwy8sAIWia2J956xv4nmKQRR79/qHYy3yez6NnHL5kqOeM68 dJ5pZZ/UsLkz3/JJlOBb2T+RSNFYYsL8Xte3zyM/cy/H949ehxC0Ut5U5Zx3l4mFIVu1 IXZw== X-Gm-Message-State: AOJu0YzKEgOveImv2LATQD7hqw13EPRFw37wMIrCoHGNt86d8ziHB+vp 91a0KepJucT2SyWkP/Nwlee59uzZIOm3OZX0K7RHBRtycT2Fzbk+dYgETBugXtUnj9qjcdZLClW hRsfeTJ6k447P1j6BjaUAeg== 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790109879687353550 X-GMAIL-MSGID: 1790109879687353550 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. */