Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp543401rdb; Thu, 8 Feb 2024 13:26:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IGwP0Cmt7KxXnUOmSHbMFQMefZxXfHXEvP+jvd1hyyVtggWc8foLpOsiHsWAyShwQ36NSfz X-Received: by 2002:a17:902:e88f:b0:1d8:f129:a0bc with SMTP id w15-20020a170902e88f00b001d8f129a0bcmr503383plg.13.1707427578784; Thu, 08 Feb 2024 13:26:18 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707427578; cv=pass; d=google.com; s=arc-20160816; b=Ia10q7o9mtzgH+gfWFxg+B87m+xtXFAuKQPG8VNEXlJQi96SBxj1m681ISYVf4LqV2 C3Y/yqGaOvuLsetSKFMIHaVplMAFYUc/hC3Wz6eDrhMMS0WLxk1GUUHFSxuHpCrfAYyP f9U4G2TZDRj9oFikoCbgIuzSI57CWRmIGCA2loBR5e0DZEbKJVq/qJGT6zZcXc1v/GMH s5VeQtfTzRcBG9+mHHufFExK9+oBSLm9DIMRcJw7hlmD75o5Nlp18ibIaFylfp0Y4zlf YlFKnNYsP0B2NX5V23GEiNdrY5Ia7pLIu/LFjowUhdouUGjrtsFg6dxxhvsnLv8Vkha3 mohA== 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=/FsUwNDlZdkXc8EiWkDbZIX2RPe8PuALhL7C0XYX/vs=; b=xERFfufmYYe5LKynp+Figd4Ccpwl5bjyl2ujB8WJZixyz0Wzk02LmK9KVD8m5Vwsff ElxFu8GxORd8eYmiC6HvD5jRiDXbbVLqiDIj6uLmFb/iNF726UTNLtMujk1wk8tU+n1u 1HmDo5Ly/YTWXI/wpO684CZbpQZeCienv0baDcrMM8iYdPB4ZTmrKukUwc5c81D0PzvQ yWnKkRZsIzle/Hzy1ghPAFcUDBHdcEJ+RewyqxXPhjAa1SURXSFpF/H6cCOWALBmkkHE QZ/m9upqoyrZSkSld1eBd6IOTwS5tLPlrA9CTQ/oBGKwCRNm2XxfpAaw9jtTm+y7z9s0 UhCA==; 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-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58713-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=2; AJvYcCXVT1uYwt4LjiF/hUQZYxvrNeRpZnvHWS9ZonmWRu24WwNXDIC+IhwwHNa0HJydbLeImvkMJ1qvIc0S/GUPLXxO7/fdU/DckO/hSF2zBA== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id i17-20020a170902eb5100b001d757bf025fsi353881pli.231.2024.02.08.13.26.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 13:26:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58713-linux.lists.archive=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=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-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58713-linux.lists.archive=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 11A2F287403 for ; Thu, 8 Feb 2024 21:24:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2EE5350A8F; Thu, 8 Feb 2024 21:22:19 +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 Content-Type: text/plain; charset="UTF-8" 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. */ -- 2.43.0.687.g38aa6559b0-goog