From mboxrd@z Thu Jan 1 00:00:00 1970 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 425EEC7115C for ; Fri, 20 Jun 2025 19:03:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D84286B008C; Fri, 20 Jun 2025 15:03:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D5BA86B0096; Fri, 20 Jun 2025 15:03:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C71A46B0098; Fri, 20 Jun 2025 15:03:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id B7A2C6B008C for ; Fri, 20 Jun 2025 15:03:54 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 64CE016134E for ; Fri, 20 Jun 2025 19:03:54 +0000 (UTC) X-FDA: 83576703588.10.E78A3CB Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf02.hostedemail.com (Postfix) with ESMTP id 1AF1E80008 for ; Fri, 20 Jun 2025 19:03:51 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=OqSdBYdP; spf=pass (imf02.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=quarantine) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1750446232; 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:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=dUGtP2n8cbKQ5lAX7UXKt00TyIe26nbilcTxEZNSxWI=; b=2m3KTwalxMnnjOnGs0TtfXqKW57c3X47g16/H9gD1BFy+8jE8HVCl1jCYzdVrECwWCi2ud cs/2dPvF1HF53NAZKpk+CpdNm+26JmgtySS2WvoTIIAEzgSmKS5ZLpuzuFqHwxNdVYxwVC wcGgK99OVCFk4yCwVPz72cym8prfIso= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=OqSdBYdP; spf=pass (imf02.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=quarantine) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1750446232; a=rsa-sha256; cv=none; b=B0q1qNN4LXZU92bQia7NSrFQNEIFKPnVujPq86HRDlM6bS9ygEtPOUFLtK0WQRtpyxNZIE GHbG3XI+03h4yzhMXoyq7g3G8NnKuKEi4F4JAt0Q+PsF3fvTCAN+8zJQmY/I0n7JXer1DM DW3VimCxWJY1ifvq/lcEWADJ9fz8X/c= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1750446231; h=from:from: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:content-transfer-encoding; bh=dUGtP2n8cbKQ5lAX7UXKt00TyIe26nbilcTxEZNSxWI=; b=OqSdBYdP3FzsgFRU/b8kmt71U8wO9TSTqA+BUiL4KTcv133EN8Ariwyuj9LoMLzGFrbVAK SNVkk5t9cT4QDu35DqkXjkOZPRI6jp3M7RRnvLfD+5Fj20dNCC52EdWBJwIAFH9yxuSU1t +8qzCa+Fl2S+MLW/iXoDzHd9rjODzi8= Received: from mail-pl1-f197.google.com (mail-pl1-f197.google.com [209.85.214.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-277-MPQnZgpqOoG_8KLGOtt89Q-1; Fri, 20 Jun 2025 15:03:49 -0400 X-MC-Unique: MPQnZgpqOoG_8KLGOtt89Q-1 X-Mimecast-MFC-AGG-ID: MPQnZgpqOoG_8KLGOtt89Q_1750446229 Received: by mail-pl1-f197.google.com with SMTP id d9443c01a7336-236445722f9so13461835ad.1 for ; Fri, 20 Jun 2025 12:03:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750446228; x=1751051028; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=dUGtP2n8cbKQ5lAX7UXKt00TyIe26nbilcTxEZNSxWI=; b=iG7TDsD0sf5D6qOZl5QN5vC7i7kxK4YY3toe+4/+Uy8lQKxDX8/41+FLeiBorjmdOi 8Yw67uTFhorIi/wkl0aeb0/TPs6FzIvbBmm9XvDuNjO5d63POI53Ju7GZ5HJTQF1yk++ XpnokNX0kh6heHbCn12WAeHCZE7BWMH6+vjz0kbfYelaVbQ1bVacTj0feqCnPsFSWF3e VfJ8QUPF5KLDWbkWINYRyDomPOpNTDb1EgKdv3X6DNsIZwN98YgREG68lABDzcaBsLC7 9yQZ2Evm5dYaySavMqbJ7yMR1UAj+FzTepGDjAh2IVYrHydZ+0FWUMH3YtvztXaGEmj6 mPig== X-Gm-Message-State: AOJu0YzWA+OhW/ajMS635OWBMx2pBbOBKjNJY2Jy591IBdv/I9ScdtHe j80/LPmavmx3zOZ20KqcWA9ErYIsJvh4pF7/l89IbxyQODd5sNAJvzGPm5w+xOy4a4s6+TgLrae ZJZCdTYnMAIvDnVZl5L3Z0e0XSkupR/mGfj2dPxHIGzQEZNC8aef0Hio2ondqlx0O6+Lh+3/Ryo bJGL81x0WOQvu8rrOri5OcZvGR7HqV4Jv6MQ== X-Gm-Gg: ASbGnctwb/FKksk7GHmY/BYTDGcEaD1su14I2SEYfep5tGmXbgjp2NAIznviI4XByqs DUgJJCXs4P2xaycdMVmaIo4LLl8lPk7BGjExfdvCLOBI3mQyTJZdIilzXHDVvSOI/5pkNeSzyVf BuMudY85IwcCUO3w3NM8MRNGPgMac8lsHoZYkeiC57dmt75TwnY289heoseEl1CG3EIzX9eEF34 +iDfOGulsWHIltmF3RqwY3M2ymOU15FCpeS5VLpH5K72wNC9XheMhfAivFV3claTTKkCrEQAcdH UCzDrkCPSEw= X-Received: by 2002:a17:903:988:b0:234:cc7c:d2e2 with SMTP id d9443c01a7336-237d97c89d0mr55547715ad.1.1750446228585; Fri, 20 Jun 2025 12:03:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHIprR2hIy8ljR+9gmTCa6DaaTxi47lCYb0fcSWA4gJP+7N78JTWg2K1+N08CEwxd3l9Bfi8Q== X-Received: by 2002:a17:903:988:b0:234:cc7c:d2e2 with SMTP id d9443c01a7336-237d97c89d0mr55547145ad.1.1750446228011; Fri, 20 Jun 2025 12:03:48 -0700 (PDT) Received: from x1.com ([85.131.185.92]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-237d8609968sm24235535ad.136.2025.06.20.12.03.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Jun 2025 12:03:47 -0700 (PDT) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Nikita Kalyazin , peterx@redhat.com, Hugh Dickins , Oscar Salvador , Michal Hocko , David Hildenbrand , Muchun Song , Andrea Arcangeli , Ujwal Kundur , Suren Baghdasaryan , Andrew Morton , Vlastimil Babka , "Liam R . Howlett" , James Houghton , Mike Rapoport , Lorenzo Stoakes , Axel Rasmussen Subject: [PATCH 0/4] mm/userfaultfd: modulize memory types Date: Fri, 20 Jun 2025 15:03:38 -0400 Message-ID: <20250620190342.1780170-1-peterx@redhat.com> X-Mailer: git-send-email 2.49.0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 6lcdGwaxprjKVQDryWHI6s5SOAq6KhzxR5n9p9RUQ5c_1750446229 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Rspam-User: X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 1AF1E80008 X-Stat-Signature: eauiqn4k8m5894bfqbog4wqu5a93unac X-HE-Tag: 1750446231-749417 X-HE-Meta: U2FsdGVkX18+XMuoxFDi1Kwq/AIBlbZLFj1bF7EoY0ZXiKJXh1Adm6BKEXRc9KrKzc2cxjml8EVD8fmYoi1mZ2j8mNfR8t1yYY3QaqbewgrSX6vT+PR9hk14QSL1MXxiZjL9iHxhwFdNcUeFskOWSJw5S6AOHNhD8dUcj/M1folTIMwdoj61gYZa/0oNNoTE7tEe0l3qmIjqeixXeqHi/6HhWb3nqx1DABmi0zTT9PlhwxNuHOZhEpeNxhPwRMUhe3157L1Ci6gBXx91/o4DZSipPZtB7IDAd5yKI7fK0HzXCx+FvJFfAW7KL1n2YYuMy8y7NYvscRIe/AcNidaaVUTysp/jbK2DAS5JAiHjq9nVbDRFqQhGtFat5mMn0zywB9ubnb9PHf81cT8gaw1++ZP4Pa517WYBjBZxZHRx9pHgo+XfBgUx2zOTBnx7LlNSGVZNnOKFkoyQlc01rGpEWEDuW552JW0iK9AG50KHfU/AWaChBeUBcuNDXNe/KYctz0ykQYxrIugDu5npb4kLZGFd4p6OrwG0k7WeyL6GJRh3utA4shs4/6vPXM0Yp1fXWIZpXEZYrm07EwOMqE9Q6Ivm1g8UB83NIlzF5oju/XwRkp7CGeq1ougyuS+6NKFtLPT8PMPWLp1qBHeEIPw85yvl/5QWF5e4H/rPQc7Rb6DJDua8o2bSycDzlrSQsOhzOQg+XxCJpKVyk+afQxqJN8DkrvuKgW3wD2YCM9l9HGtp/24qpx8v03m3kuAAj8jePLeAfzGq+iYROanGYhzwsTTmX12X6eRAW3Xcsg2NAHCE5Z5r075fsiPamxHkA2LSLZcGQlCYNf2xxfU1uRa3vhi5Sbl45zWcAQtF4Hw6tE/QWsdWHvTMRiFl8x9kA6O7//3Tea9hXnyKaT+o2IO+HLZpbadH6PNGyUTzo9O5qexYcvHZVlanoRBwHtUIdUcg4R5ZnxemuVEFoueMbml tMENX+w8 ivXHtg5uKzwnH3p2yQLa/T9s6Vo4ruN9SiUF31HXLNdZ3Z0w2+HyjPz0LmC+hT3wU0s8V3GPkqzOIqnGkk6HElynxCN45oAG/axWnqNwHuU7fxGbfQE9fSYkCQziaXrlBs3G5HKa660WXi/CeyKYISp0PlNu2CV9d2ijUkH3mIY7W0ALZrIkTk5dGTTcpGODRrqPtCyZa1NFNlsWLk+c4oE43+8nVdBJWgSCMYQeped9I7Y3nTBqXkXKEASTww9mvM5IHAAeDongvH6EJE6lKJ/kH6dHZPYpbxy1mY4XFuZwGZEUsZfa9B/MjCyiqzBN8h2QA/ibtK87h9qe3tSavMyfqFO4A1iTdpXB66s5QfsS1w5UaPPK89Fp+rATg2w+SrRUC7BvVEIQHiluMUtatZNTR7Lwmv/AitMo2nvDd1i6m/P2jC9b8OO7keY80GhIRY7E2qBAe4Tz60DJbgg4M8zOu2g== 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: List-Subscribe: List-Unsubscribe: [based on akpm/mm-new] This series is an alternative proposal of what Nikita proposed here on the initial three patches: https://lore.kernel.org/r/20250404154352.23078-1-kalyazin@amazon.com This is not yet relevant to any guest-memfd support, but paving way for it. Here, the major goal is to make kernel modules be able to opt-in with any form of userfaultfd supports, like guest-memfd. This alternative option should hopefully be cleaner, and avoid leaking userfault details into vm_ops.fault(). It also means this series does not depend on anything. It's a pure refactoring of userfaultfd internals to provide a generic API, so that other types of files, especially RAM based, can support userfaultfd without touching mm/ at all. To achieve it, this series introduced a file operation called vm_uffd_ops. The ops needs to be provided when a file type supports any of userfaultfd. With that, I moved both hugetlbfs and shmem over. Hugetlbfs is still very special that it will only use partial of the vm_uffd_ops API, due to similar reason why hugetlb_vm_op_fault() has a BUG() and so far hard-coded into core mm. But this should still be better, because at least hugetlbfs is still always involved in feature probing (e.g. where it used to not support ZEROPAGE and we have a hard-coded line to fail that, and some more). Meanwhile after this series, shmem will be completely converted to the new vm_uffd_ops API; the final vm_uffd_ops for shmem looks like this: static const vm_uffd_ops shmem_uffd_ops = { .uffd_features = __VM_UFFD_FLAGS, .uffd_ioctls = BIT(_UFFDIO_COPY) | BIT(_UFFDIO_ZEROPAGE) | BIT(_UFFDIO_WRITEPROTECT) | BIT(_UFFDIO_CONTINUE) | BIT(_UFFDIO_POISON), .uffd_get_folio = shmem_uffd_get_folio, .uffd_copy = shmem_mfill_atomic_pte, }; As I mentioned in one of my reply to Nikita, I don't like the current interface of uffd_copy(), but this will be the minimum change version of such API to support complete extrenal-module-ready userfaultfd. Here, very minimal change will be needed from shmem side to support that. Meanwhile, the vm_uffd_ops is also not the only place one will need to provide to support userfaultfd. Normally vm_ops.fault() will also need to be updated, but that's a generic function and it'll play together with the new vm_uffd_ops to make everything fly. No functional change expected at all after the whole series applied. There might be some slightly stricter check on uffd ops here and there in the last patch, but that really shouldn't stand out anywhere to anyone. For testing: besides the cross-compilation tests, I did also try with uffd-stress in a VM to measure any perf difference before/after the change; The static call becomes a pointer now. I really cannot measure anything different, which is more or less expected. Comments welcomed, thanks. Peter Xu (4): mm: Introduce vm_uffd_ops API mm/shmem: Support vm_uffd_ops API mm/hugetlb: Support vm_uffd_ops API mm: Apply vm_uffd_ops API to core mm include/linux/mm.h | 71 +++++++++++++++++++++ include/linux/shmem_fs.h | 14 ----- include/linux/userfaultfd_k.h | 58 ++++------------- mm/hugetlb.c | 19 ++++++ mm/shmem.c | 28 ++++++++- mm/userfaultfd.c | 115 +++++++++++++++++++++++++--------- 6 files changed, 217 insertions(+), 88 deletions(-) -- 2.49.0