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: 198587 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp461199dyd; Thu, 8 Feb 2024 13:24:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IFpxGcPBlALZ7is2tenCh3UvYqqQ6ucnZxobRcGAAN9Oinkb+ogMtoQ9zlkyPY145q7xMbB X-Received: by 2002:a05:6808:f92:b0:3bf:e956:173f with SMTP id o18-20020a0568080f9200b003bfe956173fmr741612oiw.50.1707427480336; Thu, 08 Feb 2024 13:24:40 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707427480; cv=pass; d=google.com; s=arc-20160816; b=O/u9J+9Q/+Zv3WS7UeT3DCAjM8caINyHx2/opiPWgHXw/lgKMvscPpCJrYO+yUPbjH eLn2hoaZpA0cLsDUZsE8jlPowzfSJG9avphRm6Mz8gbjbnOYYBODA9SLJn0yT5zb4YoC 22D/g/mNpsHAxGLTXg2cJOXUXsU5i6qgXvfW+edPHNeCxrHHdX7DR+UCSPoXybA2UN/S jSFqwdHwht3g3lmWK2G/rdAYb5bG2dGyWaj2/V+HGcftt6RB6zl2aqsMLHdYNgqmtMeI vzbUNknkIpQxkxe4DApNGcf+qXlEhdT4CKCrIVaRbNUnUXrhsz4b6XSlyc21/u+ytiPw 3XUA== 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=FeTp34JzZtDcGzw26Xy4JuyVdUXeLDl6wgD9/498E4U=; fh=n5a10P2f1wd28uzswsWr5797Y+IYNvm5tvNbkldk3Dw=; b=Mt5Swn3OjD94r5jxrVH3rTWwHQkuneZCi9k8wdMRu87qWDT4xqR5CUKx+XPZblKIzp 62lRumD6W+KpCV1pOhRjXnOj1FJetdisNROox3Q5VCjeJRcaPN89Ey17d6073igrzoyh LkZL0hVvYbgN+2VR95CzyTxIhNjHb6OzTup91Sd82PqF5fqg8iCJnz9GvXr1F5wkOprm b7uxStK2yt4FHN3l2GVadvRbwO9TigFNImutuN59kdPXKIlyTBmEO8DtGEnMI2O9PoeX hnO+HXOpWTvdZWhvkf9Y/Szk5PLtBJGHqL5CvWSx0hSUJcBmoiWk0eR17BgVrV9w1Oz1 UZaA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=BVJoV+hD; 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-58713-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58713-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=2; AJvYcCXanGUFl6IzM2zkhwRHVr21hYqTGJ9rszPbW2tDW86EAzelQxmSNvQXksweUoRkCLUh+32nHOBI9/VQNpol9uIq892SFA== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id u16-20020a05622a199000b0042c4aefa491si371827qtc.432.2024.02.08.13.24.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 13:24:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58713-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=BVJoV+hD; 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-58713-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58713-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 0E9891C23701 for ; Thu, 8 Feb 2024 21:24:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9230251C5C; Thu, 8 Feb 2024 21:22:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="BVJoV+hD" Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.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 89B174F1F4 for ; Thu, 8 Feb 2024 21:22:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707427338; cv=none; b=pta3Xs9NdJARlFHkcBOhv9G2GlQkweVXwtQr3feSzNhGdFnHTH2f6sQBWGQKchYDTO1+3QaDE/tpWT3M63ksXdTKoXEdQWCbPM8R8+tB75eyiCQYm/RHqI/rSjfGbz8eEh8lK3uTL2aSecxD2y1gE7HV8T1AR9FFfPwy05EaZ7c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707427338; c=relaxed/simple; bh=z41+dvNtRXeKCs53H9ygm12hU6JxKhETApVU+NXe4U4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=ugy6Z2m83kQeLtCN7shfiuv95NRp77A+rpQFQwPNm16PWU9Pmjh5odgAiayUXi6dE+tWXgpAdqxXqhx2SkwUlOGiJB0wgvxsNAwe+5g0jjtg1Hj8o8B4tCzuOmFtQpBTiHijN9AV11qTZwj5YiAaFwEDqIlCKWRHSMb05MISnXQ= 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=BVJoV+hD; arc=none smtp.client-ip=209.85.128.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-yw1-f201.google.com with SMTP id 00721157ae682-5ee22efe5eeso6576897b3.3 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=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=FeTp34JzZtDcGzw26Xy4JuyVdUXeLDl6wgD9/498E4U=; b=BVJoV+hD4R0hxsMHv8UySiQtBEyXUxlscxVHWN4PiVIieIeuQ4ODp6L4TlQZap4vYU 7kphAzxFH/bfog49Pg2pydlcK7UUub1Sg0z0tYte53drvCvzXFJ0X60Ik3FwvA67PUHV uspFukHOGu9AUOPBCNyvQPxOQq3kvzt+SsUYCMT2zdJC3VBk2lrQND4HgI+zLNkYZjYo B3G8ztZt3NNW7Nny2kjyBzFFP4zFKvGMyULXB0D7XSyJvjhsDC4NdeXCUs1s+A9XMfs9 ZcdU3bHMA9BGysVlkW8zu0XmEFbdrI7DUT5ym84ubfBujxuAFSw+cRji6gVT/E2KKaB/ VSSg== 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=jgfcIflMsMZiLOcUzX08ECjt5YG+5dA9W5JK9cGDHFM0CN7rIgTH2dI28+BzLWGS2g NkT6M+vGEnJzmfeXYxYvtp28qGO6zMPXF3nqxfEefLnQWEOxmHFlp9kMG2PjhtLvDxOA 3WgXfZMfs7Q0IfnIH/cudi8C9bjrq+n6aw9JJLBQgNtE4U738ofhfNEGG5Mgfx1s4mgj jRwPV77DcEmbLIsmAlCXOL8phlPMcogj03datD00bjDIaBvHxDqajIMSz3IctM1RtlOz X3XuEKkJkWjc5qVjz6VANY3ImXjB+CelqHlXu0KQEAP2fV5Fz1uw5PNKyCCg1FsGWjRN 9c9A== X-Gm-Message-State: AOJu0YwSr9qp/BHh7sp7XSTTQOmZK/QZ9OnUiULnT/pTmRYc0wX0YIn8 nkAtU8/nVRzleGjvIqF22TO96Catl3U2lW4NZ/ciqxDtaFJdZg5um+YL/KJLmgXuqJPgjyVSJy9 Er5lB3/e4H5US8wT2L0Qxtg== 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790367477502710602 X-GMAIL-MSGID: 1790367477502710602 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. */