From patchwork Tue Mar 14 22:12:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Axel Rasmussen X-Patchwork-Id: 13175059 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 98FB3C6FD1F for ; Tue, 14 Mar 2023 22:13:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 41C1A6B0074; Tue, 14 Mar 2023 18:13:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3CC366B0075; Tue, 14 Mar 2023 18:13:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 294C36B0078; Tue, 14 Mar 2023 18:13:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 1734C6B0074 for ; Tue, 14 Mar 2023 18:13:08 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id E34441C2111 for ; Tue, 14 Mar 2023 22:13:07 +0000 (UTC) X-FDA: 80568905214.22.4EF892C Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by imf19.hostedemail.com (Postfix) with ESMTP id 372AF1A0008 for ; Tue, 14 Mar 2023 22:13:06 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=kMu0VK08; spf=pass (imf19.hostedemail.com: domain of 3cfEQZA0KCL4e1ipvewqywwirksskpi.gsqpmry1-qqozego.svk@flex--axelrasmussen.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3cfEQZA0KCL4e1ipvewqywwirksskpi.gsqpmry1-qqozego.svk@flex--axelrasmussen.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1678831986; 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=v6jdDP8HhF+biD07TiydHxLy71rB2V7SdCiknod97SM=; b=1CvzYufyncFle/XX2kJxcwM68kIDk9Jnc3qOnV0Btb0aG+xvvhCKgyFuVCEGw5QW7nfO3G VhJQQZuxXZkZF9+DrB1dHW1UaZhuYnP9X0EgDRu869Q7EiykVkymgyRZ1GwurzD01B03IJ bRn2OXSHghQf+YVd3mmgant7/z8ZAJU= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=kMu0VK08; spf=pass (imf19.hostedemail.com: domain of 3cfEQZA0KCL4e1ipvewqywwirksskpi.gsqpmry1-qqozego.svk@flex--axelrasmussen.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3cfEQZA0KCL4e1ipvewqywwirksskpi.gsqpmry1-qqozego.svk@flex--axelrasmussen.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678831986; a=rsa-sha256; cv=none; b=GettYPaXvTB6Ad9zkcti7s95QpyIPSAaos5YRPUVuqmw7oKhLTZzQO8A2oKjpbNI0QiLev V1H517NM9CduKkcmwfouc3RSFBk3PJ1OJsZa6FQvkIq+o6mjIjrvFXeGx1fRE/L1bNXPzJ hpwO1SZln/vThuTiIE2qmeX9u2mTZbg= Received: by mail-yb1-f202.google.com with SMTP id ch1-20020a0569020b0100b00b3cc5b4fa9dso8044822ybb.12 for ; Tue, 14 Mar 2023 15:13:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1678831985; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=v6jdDP8HhF+biD07TiydHxLy71rB2V7SdCiknod97SM=; b=kMu0VK08lTX+5fGCRmCECylQ1aqYZ8mpt4UDxQRqVGr8ZicRslJK6RZfMREIZJzldf b2WpiHLAep+eDhqTStwebxhwBuyEH+w8tmRzHHpxwWyep5Mh0PC88Wl2/3J4e+W7pAzP IDab7doSIoA8eZfk1DgaqTEDzb8HFVVtMZh95QNo3Qmw83r20VOALCNOvfejuXwDyc90 CHLqs3kzNMn+KQjv8RdBvB11OBEEcP4lTTTzLF9fXIqz4pDf4RqUprJK1uTU3EK1dgHB BV6/EsDqJO7IonNIQMoqEv6ZVIdGnLhvdlGeLlPDsj6gw1dR15e+Snij3i1HCkBvM6z6 bOZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678831985; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=v6jdDP8HhF+biD07TiydHxLy71rB2V7SdCiknod97SM=; b=l7LqUBX8THiCWh6b1FF3fd0MRggNQuwTjuBwbNMaHeOLgsYcqBIkSsU64Em6KlwkHq RSuG1EYJgXVHH8hHz2Rl70/hssAK6fzLxZgMgBUzjk0SBMYmT9G2HNw2UPmwuAgPXRlG mTSMtzneVCRKjH2SKMEacUvfr1vhAjVQ4eh8BUUDTDnGzO/zQTxdbLHfPpkotbeBC8JX xFzO/ag1HkRoSF+gp1DXdtSCtKvE8v6Ww6CuHjEjO8cCyBQA5XLh92wiUfT4hVMxQHx/ 8x2MyqEx9SB6xowKOlV6+ZZvMQs0QkN6k1IkL18FyzjKt53A1pIgy2GvuiZHMEm2acP2 u2dw== X-Gm-Message-State: AO0yUKUMoscOqn0EY3t1AfYmMie1mwyh8UwSM9s71gxbLU+rYeqg4H0w tESXSv1dK91scDh65mBJHFxo+oYHGwwxOpHpIOOu X-Google-Smtp-Source: AK7set9RXicAeOPxAWz9Bj3vMYwmH12zqvh/H2CP6il+7wLaox5h+GED8g10IS8EvCU0qVZf8Sv5uMcqxHjOD8TzfHqN X-Received: from axel.svl.corp.google.com ([2620:15c:2d4:203:21ce:bab3:17ec:2276]) (user=axelrasmussen job=sendgmr) by 2002:a81:4512:0:b0:541:9f3a:ac46 with SMTP id s18-20020a814512000000b005419f3aac46mr6045642ywa.8.1678831985320; Tue, 14 Mar 2023 15:13:05 -0700 (PDT) Date: Tue, 14 Mar 2023 15:12:46 -0700 Mime-Version: 1.0 X-Mailer: git-send-email 2.40.0.rc1.284.g88254d51c5-goog Message-ID: <20230314221250.682452-1-axelrasmussen@google.com> Subject: [PATCH v5 0/4] mm: userfaultfd: refactor and add UFFDIO_CONTINUE_MODE_WP From: Axel Rasmussen To: Alexander Viro , Andrew Morton , Hugh Dickins , Jan Kara , "Liam R. Howlett" , Matthew Wilcox , Mike Kravetz , Mike Rapoport , Muchun Song , Nadav Amit , Peter Xu , Shuah Khan Cc: James Houghton , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, Axel Rasmussen X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 372AF1A0008 X-Stat-Signature: eec76138u8be68hahecsti66grzn3cnk X-HE-Tag: 1678831986-397780 X-HE-Meta: U2FsdGVkX18BJo2G/QbqFgYhy7chlQ5I/LEGaKZ32wUduphK9Hk4mIIIBQloT9UuknGTpVYtxiW9eIiPnY6ObFu5dS7RMyb6bvYi8JbP5PGUGS8qF6a1gf9xd9XZBuwuPRhRj6apJVP39tSyXqLXRt0RGqVFfRFK46wo9Nv6mZldM2nfL05EDBX9R9Nwg5+5ubyDYViTIrdSDkgx0KCtIK9Q/TOx8Oxpur+HslHpYvm0kcCI0xwyoD2ImQhOftrhjpLma4643ef8YCnonddsJc88RayPIxKOR+8FVhH/Kw/MS97wG+bSJQMR3s/IMAGm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pUGC1Irx03oWq7AWQSD5mxkJIoVBVbn14yO8UejcYLc5v+2D2FpvFXkd1cezP8t3r1qJo4BJMKScLYJ/qLW4MMZTf5gHjLG9pOSa+lwtEUsVapIueThIYyrrJ614CldKKAyscMjGgvkjw9gLzrrS8fhS83eyGF1OHr1y4IfOPYjka3s4QlrZj1R7/KiCAXz1cCevMXSN6fYlYk5U32l6OxY46uAtCg2TnSBDxSIwoEdqmp9dF83m2x7gfdo3nVuhbpdWrdfhGfdQc4+5qui5/IKIAgd0mXYj4nPLDavIq0NKSOZt+8M5EDeDIn0= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: This series, currently based on 6.3-rc1, is divided into two parts: - Commits 1-3 refactor userfaultfd ioctl code without behavior changes, with the main goal of improving consistency and reducing the number of function args. - Commit 4 adds UFFDIO_CONTINUE_MODE_WP. The refactors are sorted by increasing controversial-ness, the idea being we could drop some of the refactors if they are deemed not worth it. Changelog: v4->v5: - rename "uffd_flags_has_mode" to "uffd_flags_mode_is" - modify "uffd_flags_set_mode" to clear mode bits before setting new mode - update userfaultfd documentation to describe new mode flag v3->v4: - massage the uffd_flags_t implementation to eliminate all sparse warnings - add a couple inline helpers to make uffd_flags_t usage easier - drop the refactor passing `struct uffdio_range *` around (previously 4/5) - define a temporary `struct mm_struct *` in function with >=3 `vma->vm_mm` - consistent argument order between `flags` and `pagep` - expand on the use case in patch 4/4 message v2->v3: - rebase onto 6.3-rc1 - typedef a new type for mfill flags in patch 3/5 (suggested by Nadav) v1->v2: - refactor before adding the new flag, to avoid perpetuating messiness Axel Rasmussen (4): mm: userfaultfd: rename functions for clarity + consistency mm: userfaultfd: don't pass around both mm and vma mm: userfaultfd: combine 'mode' and 'wp_copy' arguments mm: userfaultfd: add UFFDIO_CONTINUE_MODE_WP to install WP PTEs Documentation/admin-guide/mm/userfaultfd.rst | 8 + fs/userfaultfd.c | 29 ++-- include/linux/hugetlb.h | 27 ++- include/linux/shmem_fs.h | 9 +- include/linux/userfaultfd_k.h | 69 +++++--- include/uapi/linux/userfaultfd.h | 7 + mm/hugetlb.c | 28 +-- mm/shmem.c | 14 +- mm/userfaultfd.c | 170 +++++++++---------- tools/testing/selftests/mm/userfaultfd.c | 4 + 10 files changed, 196 insertions(+), 169 deletions(-) --- 2.40.0.rc1.284.g88254d51c5-goog