From patchwork Thu Jun 27 10:39:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13714161 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 80B16C2BD09 for ; Thu, 27 Jun 2024 10:39:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E5C696B008A; Thu, 27 Jun 2024 06:39:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DE5BD6B008C; Thu, 27 Jun 2024 06:39:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C5E806B0092; Thu, 27 Jun 2024 06:39:42 -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 A48026B008A for ; Thu, 27 Jun 2024 06:39:42 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 2D160C1C91 for ; Thu, 27 Jun 2024 10:39:42 +0000 (UTC) X-FDA: 82276322604.02.B2EAC46 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) by imf16.hostedemail.com (Postfix) with ESMTP id 5C257180011 for ; Thu, 27 Jun 2024 10:39:40 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=W9QqNC8N; spf=pass (imf16.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.128.47 as permitted sender) smtp.mailfrom=lstoakes@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1719484772; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=tp8I88N5zTJngyTJGNfyhk0MXYhV5WZ/GtGHnw15UVU=; b=xzjrNVrDBSOEZ/W532j/8rsmKwp4Xj/7d+z1YgV/eJLMAtrTGHqolF2V1FrN3hGzsLn3lC sOb46PXVAiZFXJYXf5igJQqTrKylnQ6q4XM5YzOfVuu0xHCYyI9wQ7wq0BwCynaEB79YIb 4qcDNIP9HRxosm4vwHJoI1pzoXOe9RA= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=W9QqNC8N; spf=pass (imf16.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.128.47 as permitted sender) smtp.mailfrom=lstoakes@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719484772; a=rsa-sha256; cv=none; b=4vd1Rw2rgoXJgCmyh4Dvk1CdA7ebgQhHQ9VMV5sZwlu5HlJa2/Y7nEFnL/9pbqb6BW/4Oo ARtmWUcmZQvO0lo6Z3Yo3L5gsbr6cua9VeIoBprqXSiSFpdIHNGkXLMtoqvWwV3iP9bFJn iUcUxukm/IFl3S5+/RDS2z5/r0ftlNo= Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-421b9068274so66073915e9.1 for ; Thu, 27 Jun 2024 03:39:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719484779; x=1720089579; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=tp8I88N5zTJngyTJGNfyhk0MXYhV5WZ/GtGHnw15UVU=; b=W9QqNC8NT+Pr5t7rF7w2OguGUXCeuAQ0wvj2tDiyhrXvBUt883FKOnRViFuvUyL7yr f8grgcI9OTPyHNS7GjdbyM1TPZaVeaICmRVOkZ9ifwxzokRUMBoen/Zl1Yrj6nkRhtKf 8ROHztVU6anWGuHpIHa9TH4yVu7rNJxlE3QaYSdkr341rqgJqudYiv9ECcMNgi3DbHMg +Ds6YBiyEpwp9vLmhK+ymqSOGWqgyBBt1C5oaXJ8ctA9mUwR2xe5+y7t9r0oqrR3V0AE lcuZC+Par7NLlgjrsO0ouQh9o47R4S4b5pKb+E7VS815MgRrKqo6jLth6Y8Odo+jCUbc JiXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719484779; x=1720089579; 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=tp8I88N5zTJngyTJGNfyhk0MXYhV5WZ/GtGHnw15UVU=; b=TVa9gw2nS4CP50j001TnPPiB2nRjRqQZqi0bq6m3JvkG2aZdZjzABlBoOhcv2lLQmB qk3DTcZe+UL9xaHebcR5iy3OVGEiJtYG56hr0yQLCyvIi1PChrBadT46Z/7qsOcFKCaW ud/4wLMveZ4Ncihio7jXiFBxQajTQzdkJD7BOGAwCZoQBcSRPX94ykUTI+03PxNhC+fA mTaWMSQLag8F5qT21adDHbL2h8nOL8WkubtObjga/xmZ6vSFMcvX36AGhlm2ADKsNHQi 3RIPxXKQf4gh4xfhwKohFObpCRl+BgDzivxUmwHuRB3xCZfU/suLhqZ/1yBoXMSok3DO A3Mw== X-Forwarded-Encrypted: i=1; AJvYcCUnf7J4Cct/4eo4JWSncym6VxPBURn8/0E5FDDsemeSNgcuzPHLByFke2Km5TA2r4xjF4D9ZVmb2hw7lnF/RzA0T6g= X-Gm-Message-State: AOJu0YwHeqHFgRh+t5NNKQJtA741Ta0EzkTR7Wn62TAdex/+RYVQnMd7 Mi/nY9vOFs750trs4gglkZJo0+xG9btkIufusrrZ8xEv2M4CA1Y0 X-Google-Smtp-Source: AGHT+IGvtRZlO7kSgJ/OAiER8k6Ry3nLBU8hTMdGH2uQfnW89yXrq3HjEUQxC9bY1xw4mdxf9w9RYw== X-Received: by 2002:a05:600c:68cc:b0:425:5eec:d261 with SMTP id 5b1f17b1804b1-4255eecd2bcmr25764165e9.34.1719484778559; Thu, 27 Jun 2024 03:39:38 -0700 (PDT) Received: from lucifer.home ([2a00:23cc:d20f:ba01:bb66:f8b2:a0e8:6447]) by smtp.googlemail.com with ESMTPSA id 5b1f17b1804b1-42564bb6caasm19957195e9.33.2024.06.27.03.39.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jun 2024 03:39:37 -0700 (PDT) From: Lorenzo Stoakes To: Andrew Morton Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, "Liam R . Howlett" , Vlastimil Babka , Matthew Wilcox , Alexander Viro , Christian Brauner , Jan Kara , Eric Biederman , Kees Cook , Suren Baghdasaryan , Lorenzo Stoakes Subject: [RFC PATCH 0/7] Make core VMA operations internal and testable Date: Thu, 27 Jun 2024 11:39:25 +0100 Message-ID: X-Mailer: git-send-email 2.45.1 MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 5C257180011 X-Stat-Signature: xiro4g6jo5cgf4t4k3nwnqcetcgkg1r9 X-HE-Tag: 1719484780-448860 X-HE-Meta: U2FsdGVkX19EQqmfjoaU8SYJ2f4YNL3zCBS7Sb5QfhANKqPLrVAJYMbJnXABBYwTPIYAeTxQeMN8etUDMjXIBwbxcSfBzZLnHkzXC15YGzuKhfugdayGcnYElCWxxgafmWslakshc5NXCjSGKNGqdbqCwzqDmw4GG3xmfoEKWy3V6V7AgRF79AWTlDTWfssFMQ/jVDyjqmiXFXJIFW6A67+9e4tD8oQgIV4E7RmIctCiAgVIdNmKgLDWXjM3cDjMvRmK6d1Y1Hs9gcH3cLWQaqQ+4p3Q453h9XOJQf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kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: There are a number of "core" VMA manipulation functions implemented in mm/mmap.c, notably those concerning VMA merging, splitting, modifying, expanding and shrinking, which logically don't belong there. More importantly this functionality represents an internal implementation detail of memory management and should not be exposed outside of mm/ itself. This patch series isolates core VMA manipulation functionality into its own file, mm/vma.c, and provides an API to the rest of the mm code in mm/vma.h. Importantly, it also carefully implements mm/vma_internal.h, which specifies which headers need to be imported by vma.c, leading to the very useful property that vma.c depends only on mm/vma.h and mm/vma_internal.h. This is useful, because we can then re-implement vma_internal.h in userland, stubbing out and adding shims for kernel mechanisms as required, and then can directly and very easily unit test internal VMA functionality. This patch series takes advantage of existing shim logic and full userland maple tree support contained in tools/testing/radix-tree/ and tools/include/linux/, separating out shared components of the radix tree implementation to provide this testing. Kernel functionality is stubbed and shimmed as needed in tools/testing/vma/ which contains a fully functional userland vma_internal.h file and which imports mm/vma.c and mm/vma.h to be directly tested from userland. A simple, skeleton testing implementation is provided in tools/testing/vma/main.c as a proof-of-concept, asserting that simple VMA merge, modify (testing split), expand and shrink functionality works correctly. Lorenzo Stoakes (7): userfaultfd: move core VMA manipulation logic to mm/userfaultfd.c mm: move vma_modify() and helpers to internal header mm: unexport vma_expand() / vma_shrink() mm: move internal core VMA manipulation functions to own file MAINTAINERS: Add entry for new VMA files tools: separate out shared radix-tree components tools: add skeleton code for userland testing of VMA logic MAINTAINERS | 14 + fs/exec.c | 26 +- fs/userfaultfd.c | 160 +- include/linux/mm.h | 104 +- include/linux/userfaultfd_k.h | 19 + mm/Makefile | 2 +- mm/gup.c | 1 + mm/huge_memory.c | 1 + mm/internal.h | 160 +- mm/madvise.c | 1 + mm/memory.c | 1 + mm/mempolicy.c | 1 + mm/mlock.c | 1 + mm/mmap.c | 1808 +---------------- mm/mmu_notifier.c | 2 + mm/mprotect.c | 1 + mm/mremap.c | 1 + mm/mseal.c | 2 + mm/rmap.c | 1 + mm/userfaultfd.c | 170 ++ mm/vma.c | 1766 ++++++++++++++++ mm/vma.h | 356 ++++ mm/vma_internal.h | 143 ++ tools/testing/radix-tree/Makefile | 68 +- tools/testing/radix-tree/maple.c | 14 +- tools/testing/radix-tree/xarray.c | 9 +- tools/testing/shared/autoconf.h | 2 + tools/testing/{radix-tree => shared}/bitmap.c | 0 tools/testing/{radix-tree => shared}/linux.c | 0 .../{radix-tree => shared}/linux/bug.h | 0 .../{radix-tree => shared}/linux/cpu.h | 0 .../{radix-tree => shared}/linux/idr.h | 0 .../{radix-tree => shared}/linux/init.h | 0 .../{radix-tree => shared}/linux/kconfig.h | 0 .../{radix-tree => shared}/linux/kernel.h | 0 .../{radix-tree => shared}/linux/kmemleak.h | 0 .../{radix-tree => shared}/linux/local_lock.h | 0 .../{radix-tree => shared}/linux/lockdep.h | 0 .../{radix-tree => shared}/linux/maple_tree.h | 0 .../{radix-tree => shared}/linux/percpu.h | 0 .../{radix-tree => shared}/linux/preempt.h | 0 .../{radix-tree => shared}/linux/radix-tree.h | 0 .../{radix-tree => shared}/linux/rcupdate.h | 0 .../{radix-tree => shared}/linux/xarray.h | 0 tools/testing/shared/maple-shared.h | 9 + tools/testing/shared/maple-shim.c | 7 + tools/testing/shared/shared.h | 34 + tools/testing/shared/shared.mk | 68 + .../testing/shared/trace/events/maple_tree.h | 5 + tools/testing/shared/xarray-shared.c | 5 + tools/testing/shared/xarray-shared.h | 4 + tools/testing/vma/.gitignore | 7 + tools/testing/vma/Makefile | 18 + tools/testing/vma/errors.txt | 0 tools/testing/vma/generated/autoconf.h | 2 + tools/testing/vma/linux/atomic.h | 19 + tools/testing/vma/linux/mmzone.h | 37 + tools/testing/vma/main.c | 161 ++ tools/testing/vma/vma.h | 3 + tools/testing/vma/vma_internal.h | 843 ++++++++ tools/testing/vma/vma_stub.c | 6 + 61 files changed, 3800 insertions(+), 2262 deletions(-) create mode 100644 mm/vma.c create mode 100644 mm/vma.h create mode 100644 mm/vma_internal.h create mode 100644 tools/testing/shared/autoconf.h rename tools/testing/{radix-tree => shared}/bitmap.c (100%) rename tools/testing/{radix-tree => shared}/linux.c (100%) rename tools/testing/{radix-tree => shared}/linux/bug.h (100%) rename tools/testing/{radix-tree => shared}/linux/cpu.h (100%) rename tools/testing/{radix-tree => shared}/linux/idr.h (100%) rename tools/testing/{radix-tree => shared}/linux/init.h (100%) rename tools/testing/{radix-tree => shared}/linux/kconfig.h (100%) rename tools/testing/{radix-tree => shared}/linux/kernel.h (100%) rename tools/testing/{radix-tree => shared}/linux/kmemleak.h (100%) rename tools/testing/{radix-tree => shared}/linux/local_lock.h (100%) rename tools/testing/{radix-tree => shared}/linux/lockdep.h (100%) rename tools/testing/{radix-tree => shared}/linux/maple_tree.h (100%) rename tools/testing/{radix-tree => shared}/linux/percpu.h (100%) rename tools/testing/{radix-tree => shared}/linux/preempt.h (100%) rename tools/testing/{radix-tree => shared}/linux/radix-tree.h (100%) rename tools/testing/{radix-tree => shared}/linux/rcupdate.h (100%) rename tools/testing/{radix-tree => shared}/linux/xarray.h (100%) create mode 100644 tools/testing/shared/maple-shared.h create mode 100644 tools/testing/shared/maple-shim.c create mode 100644 tools/testing/shared/shared.h create mode 100644 tools/testing/shared/shared.mk create mode 100644 tools/testing/shared/trace/events/maple_tree.h create mode 100644 tools/testing/shared/xarray-shared.c create mode 100644 tools/testing/shared/xarray-shared.h create mode 100644 tools/testing/vma/.gitignore create mode 100644 tools/testing/vma/Makefile create mode 100644 tools/testing/vma/errors.txt create mode 100644 tools/testing/vma/generated/autoconf.h create mode 100644 tools/testing/vma/linux/atomic.h create mode 100644 tools/testing/vma/linux/mmzone.h create mode 100644 tools/testing/vma/main.c create mode 100644 tools/testing/vma/vma.h create mode 100644 tools/testing/vma/vma_internal.h create mode 100644 tools/testing/vma/vma_stub.c --- 2.45.1