From patchwork Mon Jan 29 19:35:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lokesh Gidra X-Patchwork-Id: 13536307 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5C9E9C47DA9 for ; Mon, 29 Jan 2024 19:35:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C3E166B0085; Mon, 29 Jan 2024 14:35:23 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BED0F6B0087; Mon, 29 Jan 2024 14:35:23 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ADCA06B0088; Mon, 29 Jan 2024 14:35:23 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 9DDD76B0085 for ; Mon, 29 Jan 2024 14:35:23 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 435AC1A0B09 for ; Mon, 29 Jan 2024 19:35:23 +0000 (UTC) X-FDA: 81733352526.15.8A9EB03 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by imf21.hostedemail.com (Postfix) with ESMTP id 88AA01C0010 for ; Mon, 29 Jan 2024 19:35:21 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="mq/AKMV3"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf21.hostedemail.com: domain of 3-P23ZQsKCAkuxtn1qprm0jpxxpun.lxvurw36-vvt4jlt.x0p@flex--lokeshgidra.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3-P23ZQsKCAkuxtn1qprm0jpxxpun.lxvurw36-vvt4jlt.x0p@flex--lokeshgidra.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706556921; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=Y47b8IapUuQ52NiyXedK/xqkWWUKqV6XNeLrQIpcJlU=; b=4zGMXIQbwFNv+GBXXMDwpoPf0ECOENXYmz5df/W03kppl7XfYh5F4ioenJqy6f0GTeFzI9 sGBpq/rO/i0h5PBxb7qlleZgqV1+PmyV8/ygWrSwSOiSfsdjmR5qi226nfPDvfm7xiklSg utaCneQOPXYZup87/ZtmR1mcwWjR5m8= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="mq/AKMV3"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf21.hostedemail.com: domain of 3-P23ZQsKCAkuxtn1qprm0jpxxpun.lxvurw36-vvt4jlt.x0p@flex--lokeshgidra.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3-P23ZQsKCAkuxtn1qprm0jpxxpun.lxvurw36-vvt4jlt.x0p@flex--lokeshgidra.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706556921; a=rsa-sha256; cv=none; b=EY96Yx0c8h9neYMx1G8kaQl93MWnalLSxiPBglyIM27MN50gz61b5LkOLk2nKReLy9uSn8 +uLNoKbKaWn7c6XRVaL9TnQN1VAFCcAsnUcQgK8YDrKgXF1tmv+9lsK4me7VSMgj6raejV sHrJ3cXYPVj9jmFlAOer/PiM/j+/Wfg= Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-dbf618042daso5057088276.0 for ; Mon, 29 Jan 2024 11:35:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706556920; x=1707161720; darn=kvack.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=Y47b8IapUuQ52NiyXedK/xqkWWUKqV6XNeLrQIpcJlU=; b=mq/AKMV3ieqwyMAlqc7okxq+yp4aSBUnMlKVhYlIK7H2G8ujADVjximtAkHOyufXwA oL6vSabCzcU5a4cBbEGP+CyZyrKSKxEhEApQEBRTAQW5SibRke44WtkqZN/TgI5TC/u0 xv7XWQT1an5ZAvq0YTXcP6sASfRcHDlcYv1UhoNHXkOJ/7wD/RzepHH2ZZUEqWOTCPkf CvowDCjIVBqqEKseVWSyWLpZksxvIbFG9nfUxujCNX7bxbQbx9x0hVp6LsL75SKlVcJP 29QvdGhY2A3ry46mfqIPiA8I372kWKANeVG2fKB+6YxlV+eilTmT7feE01cVnaNwCui0 yEFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706556920; x=1707161720; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=Y47b8IapUuQ52NiyXedK/xqkWWUKqV6XNeLrQIpcJlU=; b=oiZbAi1bzYNLyJRLGwSGHSeQsn56RefaRs4GFIBj1uIvVFQExdSp4p56/3zdrgopji Joe1oR9DDLS2fxxsAkDCWvAP9DFYBgS+0+XuTjrLhJl6a7EZ4QphU7Re2O4ACzw5fMGe vs58xR2TFV1wZczWg7ebp/wYeh7ztfY+9sOmhkGhwpbLKaFlnpTUxOLoppquYDCT7S9+ uPbnaT2xJv7lmv+J0GoEjGtfYNDoOJPVjkHM7WXxfJmk99AmbVLj5bAFlh4Xa9/s4HBL fm6pSKNOECMJAxT4aQ6AelyZlK+5FABOTwupc5gnuY7gKbiHKBQhbRI3jUGM/v5A1pp9 m+2Q== X-Gm-Message-State: AOJu0YwYBFhUTsZgCZFbJzCyfK5l5jNvOHR77t7mE0uDGD1bkk9qGlN7 BMBOy0+6I7L4qhSzoExdEpevkd6DC9himq7JI9x6kgqfEUb4lm5y32cN9CCtYzQCj1sbvtq6OIf iBil8q+ITj7FidHJrRHdkhQ== X-Google-Smtp-Source: AGHT+IFpUlsNWwzEIDjzWN6N56lWLkRvPKg+4gqK1HK7WRmXRpoMLHM95bZ5V0i0zZbH36vyMnKU3/xtEdcui8mBFg== X-Received: from lg.mtv.corp.google.com ([2620:15c:211:202:9b1d:f1ee:f750:93f1]) (user=lokeshgidra job=sendgmr) by 2002:a05:6902:2604:b0:dc2:23db:1bc8 with SMTP id dw4-20020a056902260400b00dc223db1bc8mr443578ybb.3.1706556920762; Mon, 29 Jan 2024 11:35:20 -0800 (PST) Date: Mon, 29 Jan 2024 11:35:09 -0800 Mime-Version: 1.0 X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog Message-ID: <20240129193512.123145-1-lokeshgidra@google.com> Subject: [PATCH v2 0/3] per-vma locks in userfaultfd 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 X-Rspam-User: X-Stat-Signature: k5gqrq4htquehpnnqbu4ffw36h9danjq X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 88AA01C0010 X-HE-Tag: 1706556921-122392 X-HE-Meta: U2FsdGVkX1/qob7oYAQDKz9OGgMvj1t9a5pCvnRbfjPVlwxdjqFfeagji1yyOP3dQQp5YejG4WisdYlv7SEWIX2Yl+detU/mjsY9P8VFVwpe26qCVks1b+Z0d+fTY954iZquRM9xp05j/vgnCPUuaEJJ06+2Qr5Dh2jL/xwvaLDH3UGGESuxOTy6A6Ju5EevfLaKzIo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q7je9fPchc22BrPLd+S2s9c3Jhn4qhDOQ20v2walTFip7kdlVOasyXUthG/M8o3EM8zmKXjX6OTtpWczZ/sDu1fOnxM8t1oMlZh6G6dSfB3QNBi2dLH74Ve7VaaB8r9xsUPritB08fJsIixyvslpM2ntspBe7uCiex/S6Y4IU7nSeKZx1m22m/U1j+as+bn51im5tzm14KNl1IwiVgxoIvClRw68u/IsdmFTOhxeqlTtKVHmG27PVauQ1OC2b6V5DrBaMZjB6oXXutpOOIRbxcOo/ZJCibFQXz0eKARH1Q3HFlNkITUopQJxk9awjwrWLWgR1eY5n3Md7xbTPP+7+GclZcjwTXbbxWDW0FIpBu7U31kA9oDyO3UWk8nI9etgfN6lc/EFyJYylTypv88FN2rxI= X-Bogosity: Ham, tests=bogofilter, spamicity=0.011016, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Performing userfaultfd operations (like copy/move etc.) in critical section of mmap_lock (read-mode) causes significant contention on the lock when operations requiring the lock in write-mode are taking place concurrently. We can use per-vma locks instead to significantly reduce the contention issue. Changes since v1 [1]: - rebase patches on 'mm-unstable' branch [1] https://lore.kernel.org/all/20240126182647.2748949-1-lokeshgidra@google.com/ Lokesh Gidra (3): userfaultfd: move userfaultfd_ctx struct to header file userfaultfd: protect mmap_changing with rw_sem in userfaulfd_ctx userfaultfd: use per-vma locks in userfaultfd operations fs/userfaultfd.c | 86 ++++--------- include/linux/userfaultfd_k.h | 75 ++++++++--- mm/userfaultfd.c | 229 ++++++++++++++++++++++------------ 3 files changed, 229 insertions(+), 161 deletions(-)