Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp595377rdb; Mon, 29 Jan 2024 11:36:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IF8sbohb4cfM8ukNmbW6ekjRx0LyYqwKkFMCN6Kk3AKJx2PrY8HT8IfnKbmr8SoaAAOlVV+ X-Received: by 2002:a05:620a:1aa5:b0:783:9079:93a8 with SMTP id bl37-20020a05620a1aa500b00783907993a8mr7068073qkb.18.1706556988385; Mon, 29 Jan 2024 11:36:28 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706556988; cv=pass; d=google.com; s=arc-20160816; b=C/6hHcQ7zd7NF1gFNvA37eVYLh9MvcOmwBGOZkv8IB52mfLQHl/tuEzPY2lAiD58fj Pw0fhF7FTljs5+qPr3G+hpYgkf5itVZzMpye6Y/p6LVivDyJm8z5YSLaslzyu0U9RyUz G2OnAJv0AqZXw1aR8WlcbASThUV02DYTHGFKVt6DFCqoPgAMq0T7Hjj49OYwytfVo9+n NfmqREIZQ8wF3JgDqHzIjo8JPckDRodmD2ZVvPNp1RWd+0rDQNMnNe8QBk81pkkHdlmB bwe6/laF1NayZmfoBxsnqOqJdMumevFumvaBuWkOEtm0au6dQ/G0awlb2WIMWDPIGMuk DpOg== 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=RxV5wBXLAd7sIIElP90tsYG05NDDw/o/tErBcn9qBHI=; fh=YpYg+AMOLH4GRgVOvnwFLenCYLn09uoxMCo5ibUfZzo=; b=WzH//O4YKsUGZp/XMb+7rEfxD9hONLErPlRST2loItTx6LlUODxoHQfUzeUf4odkCt PgA+8+pCdrEXj7FpByvV4Yln6Ies5e1RXdsujOrEt4FO0iR+iZpn+cIboMz2OuR0O28e 3oHILC+Ik6/0v64BJ3nD0/SZb+StA1GOEbIuzZXHATgXXQJsd/6wNhVtjS0C6dnDOQgg JIgUr+Be1flgFW2daj2++A/QG4z+Xc7qNGtq9u10zQkbdcjVjLu3Z/fjYC9eXg/od6Xo TAd40mer4bgn4D0Ff6Jh8kVX9iR5qORdAKTY834mQ7CS2VQMMMQgXnUhcROQD6M0udpQ w0Dg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=DL1DtO5C; 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-43418-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-43418-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id d1-20020a37c401000000b00783da2644bdsi7348964qki.768.2024.01.29.11.36.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jan 2024 11:36:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-43418-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=DL1DtO5C; 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-43418-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-43418-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id E26F81C24640 for ; Mon, 29 Jan 2024 19:36:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 751DC13D51E; Mon, 29 Jan 2024 19:35:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="DL1DtO5C" Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (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 2A91C7604E for ; Mon, 29 Jan 2024 19:35:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706556928; cv=none; b=lE4U5TxafO7q3+GwYpz89dN/dOvbzvzCFoj7RFpOK0IMNkl1HTiYZWPEIu1p8tT2XFCRzMOhVq6qEq0xTu4+om9C95sbpUzxQC/xi8jn1kqAUbIHJxcPjgTH9k1LV7Kss4Q19Qol3LF4glQwpujvfF/LCcxuaToYPOTdYSPi0Sc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706556928; c=relaxed/simple; bh=OJgQ1qhLDabP6L30mWXu4b8oGn7mXavl1NGjOvY9bUw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=f+5ls7WMbVXEnNi2tratTCQab++HsuTzDEjU8vFpqKbA2Jllt/LHyxt/lnc5kz0yqtKpFLZHmF+a1HgjNaVODl/IQrNf9I14WABgofW/xwkOYjj+N7vcR4/A41yHldcrQk36D0gIFTzvbeKMHa7q+61vsmLrxeuobcasNGU82Xs= 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=DL1DtO5C; arc=none smtp.client-ip=209.85.219.202 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-f202.google.com with SMTP id 3f1490d57ef6-d9a541b720aso5607089276.0 for ; Mon, 29 Jan 2024 11:35:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706556925; x=1707161725; 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=RxV5wBXLAd7sIIElP90tsYG05NDDw/o/tErBcn9qBHI=; b=DL1DtO5C+sqoconRImf9YTESx0JrJIX1W8P3iTJ9x0GUqaWsn4E/JoNceR7l4Mrhs6 UK2z2JPaW6mFs9PZcZ2IFNgwAFWLKBJMUIEvhS70yHiFabWLRB99YQqLo5HrLTUHL5l9 6Unwt8BmjSIfvL/iRqUo35AH2I+SH6ER+MIH8wPJH1gtJGWNe7isKWvMQy+0cPostTpb LVsHrqXboFKhaQ/7K9H2S4NDTOa67uDZt40l/Pjp/c47FPTALOICEMM72F01fagGGuOi hEtKMYD29gOActz05USiM3f63Cawi9tL/XmSx77AuXhASLhbnjH7gchFkejL6A1d5VlX 7g6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706556925; x=1707161725; 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=RxV5wBXLAd7sIIElP90tsYG05NDDw/o/tErBcn9qBHI=; b=GrstLsnjDQd8SGVlsR0CBCYPAtCvhbdSsqbdfu2LnhFiUnjOS0HB+8acA6VAufALvH HTFW5ppajYCPWVZGGH2EGuXWKfdGp2VNfSPClpWBVZs5oN+eV+CzYNirZ2G1MJ8TOeAm YchY6sSudv31p87p4nA/J2t62vMU2k/FjIlhXvLK6ZL+Xn0c8+bY4i8nSJ77fEwkVmSm lMqET4cRhGOSh7mWro2HhJcl0bXf8oHfDzlair9aN4PWogFl9kvDScN7PuEY5XTWbR4P S7ywU6nUrUvEh6ys6dJiwoZWwCmmsM1PzSwxxDxXd6I/tQnRW6mX1WyZQOcl+p6sJi7p QMkQ== X-Gm-Message-State: AOJu0YyuDeFAAELwhQXt4LFdlYQ/bxtHW3sWLgmODCzQyO1+KwBzUEYz Vs7oasFWqPtTamZ5TgRnw7WGXLvnmjrpd1BknVKziXkQynHFUaYNpdwYXA/deV+r7Y+kLjOVjqN YuwSOu/A+0T7DuDmTFqdCAw== X-Received: from lg.mtv.corp.google.com ([2620:15c:211:202:9b1d:f1ee:f750:93f1]) (user=lokeshgidra job=sendgmr) by 2002:a05:6902:2611:b0:dc2:4ab7:3d89 with SMTP id dw17-20020a056902261100b00dc24ab73d89mr2460415ybb.1.1706556925300; Mon, 29 Jan 2024 11:35:25 -0800 (PST) Date: Mon, 29 Jan 2024 11:35:10 -0800 In-Reply-To: <20240129193512.123145-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: <20240129193512.123145-1-lokeshgidra@google.com> X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog Message-ID: <20240129193512.123145-2-lokeshgidra@google.com> Subject: [PATCH v2 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 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 --- 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