Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp842121rdb; Mon, 29 Jan 2024 23:13:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IGxFsgDMMZeilP8UK8Wh1M991FloZHMEIpM62wH9NhDFA2+P/41ZwQVhirS+ja+W0u7vM9d X-Received: by 2002:a17:906:2687:b0:a35:f9b6:fd95 with SMTP id t7-20020a170906268700b00a35f9b6fd95mr1725392ejc.2.1706598803158; Mon, 29 Jan 2024 23:13:23 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706598803; cv=pass; d=google.com; s=arc-20160816; b=Ko2Cw5Oy8S18MqwFhazZOW4eeJ7XfOSSGMgXDwaGAfZun/+vmKnoP223Jjh+GCq4Cc 5VECGAXbn/xJq2MJQ53VIDR28076xj1zbhei9S4VDuxLjqERb6QFr/vHEybcEdgUXKZ7 W6Cjg0vVaU9Lw0pzYqWEl82eb1fbwzfNXl3N9Zk36Hc4JhtbQEJr6k40cCg9BEKcU35Y iwS8keQqdeAj2F6/ri06eXLGPNYBeKL7YGKwoIoMJaK7dl5QtzoPI5rpxv3qhJS0tBhq kXbwOCnCscrtEp8ibw4HkVS0NtkBRV1/Hv0SANDl3hJNxHQWv2CREfuOjsQKRjtTTjdo Vq1g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=iEFdq6DFhKK6EKe8MRU8y0jWU6sWDWsyvnbywOJJixk=; fh=S4BO/suAdLWAFQgJk6yDHQZymbD7cURKvsqevmbCJFk=; b=mS2lIZDF12aBy3V6hgpiv5UNYSKNeGAGWMgKUgOxeJn8kyyzZkxZPlueWi2hpOnYSa kEPxG+/3c7yT3kuOhHxfFYa0Afr6rKrkueq0KdPo4aXorQ3wLvBitXBHY94qkjVmVD0V qGhSokT1QkIK3tDqoZlEKnFLhBR9lTA0DOmvoGC+o1xJ3vmVIlb5DZaQ0MV2XWwgb16d x8bbKL9eAq0SIGv1HVtwezO5z644GO3HsAJ1AyMKnIKssrVgeQhJeR5XBFa6LGkZB9vz 9VFUE71bQe/A2PTnVX+7nyjV7TVGh76GNJjs5VzMAOPWqVKB6cKiYQq5PDnwLJrcdTFF b8+w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=URcyGOpC; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-44026-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-44026-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id x11-20020a1709065acb00b00a3177972d7asi4192728ejs.683.2024.01.29.23.13.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jan 2024 23:13:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-44026-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=URcyGOpC; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-44026-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-44026-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 am.mirrors.kernel.org (Postfix) with ESMTPS id B8A5A1F24274 for ; Tue, 30 Jan 2024 07:13:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9B6DC4F1F3; Tue, 30 Jan 2024 07:13:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="URcyGOpC" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B60844500D; Tue, 30 Jan 2024 07:13:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706598790; cv=none; b=rnfn7gF9jQ2JnuLhzQBJZoEWpG+qWG4LHD4JX5h36fD4Rlv1KQwirkF/P+DUqdUfQnlwnM9VBVt8QvYavIzSUKfilIrAXaa65ED0yS6gf9+5nJkN2HPaVK1v1VwXtQO+UdFKinN0k4lXFJA3TlwhhXCsC0HnsIonP8iscOJhQmA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706598790; c=relaxed/simple; bh=oGSi+REcwrs/+BSbLE+SMirHJl4MYtMgh21giqxANxg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=tNFHrVsLgOrPpOq7bSDK2Fw1/3NVQSxDyg12sbntM6rcJlaM5UFCMNQzjPbzb94PnrtzZHiJuYgoPj3vwIopIx0bDXNpbWK3mTKZQ3Ybxla5/SUY/wjjluzu7NygPk9MrTkEpHUJT8OmxJezvw7H6rc37eYW/oZD9D/IVqiVEow= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=URcyGOpC; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id CA419C433F1; Tue, 30 Jan 2024 07:13:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706598790; bh=oGSi+REcwrs/+BSbLE+SMirHJl4MYtMgh21giqxANxg=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=URcyGOpCzoFfcwqq4+CtiY0zXkzUO9VlQY0zXZlUmdU/BCjQzauXj54jpM831meQO K0X1PYj3jHRpSoJBdLjon7W6D2gr3dBeYY1I2DTnEoSy+3ntGiStVHJHGQqFrqnEuE qXDWE3IL4e5+sBByPpuqYshj25gNok0773hZ96ypP1OHtQi0h4a69v/CmfdSUR9V9l HMzflFgu+NjI0uhjuYV6FPn99jcAb5zSySMLqC/9UPS+6kBg4zCBUzzA14UphTx2LD b2410FHjjncrH15pUsiYUW+Y1e9XIOIkrr9OMjhE3FNyqpp/Ly5bT2S6h6ElteKOZN iQtMM9dXffgnQ== Date: Tue, 30 Jan 2024 09:12:44 +0200 From: Mike Rapoport To: Lokesh Gidra Cc: akpm@linux-foundation.org, 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 Subject: Re: [PATCH v2 1/3] userfaultfd: move userfaultfd_ctx struct to header file Message-ID: References: <20240129193512.123145-1-lokeshgidra@google.com> <20240129193512.123145-2-lokeshgidra@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240129193512.123145-2-lokeshgidra@google.com> On Mon, Jan 29, 2024 at 11:35:10AM -0800, Lokesh Gidra wrote: > Moving the struct to userfaultfd_k.h to be accessible from > mm/userfaultfd.c. There are no other changes in the struct. Just a thought, it maybe worth to move all of fs/userfaultfd.c to mm/userfaultfd.c ... > 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.429.g432eaa2c6b-goog > -- Sincerely yours, Mike.